Skip to content

Commit

Permalink
Result cache - hash autoload file and bootstrap files
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed Feb 19, 2021
1 parent 527269a commit 3457e58
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 2 deletions.
1 change: 1 addition & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -418,6 +418,7 @@ services:
stubFiles: %stubFiles%
usedLevel: %usedLevel%
cliAutoloadFile: %cliAutoloadFile%
bootstrapFiles: %bootstrapFiles%

-
class: PHPStan\Analyser\ResultCache\ResultCacheClearer
Expand Down
27 changes: 25 additions & 2 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
class ResultCacheManager
{

private const CACHE_VERSION = 'v7-installed-php';
private const CACHE_VERSION = 'v8-executed-hash';

private ExportedNodeFetcher $exportedNodeFetcher;

Expand All @@ -37,6 +37,9 @@ class ResultCacheManager

private ?string $cliAutoloadFile;

/** @var string[] */
private array $bootstrapFiles;

/** @var array<string, string> */
private array $fileHashes = [];

Expand All @@ -52,6 +55,7 @@ class ResultCacheManager
* @param string[] $stubFiles
* @param string $usedLevel
* @param string|null $cliAutoloadFile
* @param string[] $bootstrapFiles
* @param array<string, string> $fileReplacements
*/
public function __construct(
Expand All @@ -63,6 +67,7 @@ public function __construct(
array $stubFiles,
string $usedLevel,
?string $cliAutoloadFile,
array $bootstrapFiles,
array $fileReplacements
)
{
Expand All @@ -74,6 +79,7 @@ public function __construct(
$this->stubFiles = $stubFiles;
$this->usedLevel = $usedLevel;
$this->cliAutoloadFile = $cliAutoloadFile;
$this->bootstrapFiles = $bootstrapFiles;
$this->fileReplacements = $fileReplacements;
}

Expand Down Expand Up @@ -553,7 +559,7 @@ private function getMeta(?array $projectConfigArray): array
'analysedPaths' => $this->analysedPaths,
'composerLocks' => $this->getComposerLocks(),
'composerInstalled' => $this->getComposerInstalled(),
'cliAutoloadFile' => $this->cliAutoloadFile,
'executedFilesHashes' => $this->getExecutedFileHashes(),
'phpExtensions' => $extensions,
'stubFiles' => $this->getStubFiles(),
'level' => $this->usedLevel,
Expand All @@ -578,6 +584,23 @@ private function getFileHash(string $path): string
return $hash;
}

/**
* @return array<string, string>
*/
private function getExecutedFileHashes(): array
{
$hashes = [];
if ($this->cliAutoloadFile !== null) {
$hashes[$this->cliAutoloadFile] = $this->getFileHash($this->cliAutoloadFile);
}

foreach ($this->bootstrapFiles as $bootstrapFile) {
$hashes[$bootstrapFile] = $this->getFileHash($bootstrapFile);
}

return $hashes;
}

private function getPhpStanVersion(): string
{
try {
Expand Down

0 comments on commit 3457e58

Please sign in to comment.