Skip to content

Commit

Permalink
DX: Cache optimisation (#7985)
Browse files Browse the repository at this point in the history
  • Loading branch information
keradus committed May 6, 2024
1 parent 6a9351f commit c3af946
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions src/Cache/CacheManagerInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,4 +24,6 @@ interface CacheManagerInterface
public function needFixing(string $file, string $fileContent): bool;

public function setFile(string $file, string $fileContent): void;

public function setFileHash(string $file, string $hash): void;
}
7 changes: 5 additions & 2 deletions src/Cache/FileCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,9 +103,12 @@ public function needFixing(string $file, string $fileContent): bool

public function setFile(string $file, string $fileContent): void
{
$file = $this->cacheDirectory->getRelativePathTo($file);
$this->setFileHash($file, $this->calcHash($fileContent));
}

$hash = $this->calcHash($fileContent);
public function setFileHash(string $file, string $hash): void
{
$file = $this->cacheDirectory->getRelativePathTo($file);

if ($this->isDryRun && $this->cache->has($file) && $this->cache->get($file) !== $hash) {
$this->cache->clear($file);
Expand Down
3 changes: 3 additions & 0 deletions src/Cache/NullCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

/**
* @author Andreas Möller <am@localheinz.com>
* @author Dariusz Rumiński <dariusz.ruminski@gmail.com>
*
* @internal
*/
Expand All @@ -27,4 +28,6 @@ public function needFixing(string $file, string $fileContent): bool
}

public function setFile(string $file, string $fileContent): void {}

public function setFileHash(string $file, string $hash): void {}
}
4 changes: 2 additions & 2 deletions src/Runner/Runner.php
Original file line number Diff line number Diff line change
Expand Up @@ -154,8 +154,8 @@ private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResu
$tokens = Tokens::fromCode($old);
$oldHash = $tokens->getCodeHash();

$newHash = $oldHash;
$new = $old;
$newHash = $oldHash;

$appliedFixers = [];

Expand Down Expand Up @@ -266,7 +266,7 @@ private function fixFile(\SplFileInfo $file, LintingResultInterface $lintingResu
}
}

$this->cacheManager->setFile($name, $new);
$this->cacheManager->setFileHash($name, $newHash);

$this->dispatchEvent(
FixerFileProcessedEvent::NAME,
Expand Down
5 changes: 5 additions & 0 deletions tests/Runner/FileFilterIteratorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -229,6 +229,11 @@ public function setFile(string $file, string $fileContent): void
{
throw new \LogicException('Not implemented.');
}

public function setFileHash(string $file, string $hash): void
{
throw new \LogicException('Not implemented.');
}
};
}
}

0 comments on commit c3af946

Please sign in to comment.