Skip to content

Commit

Permalink
Result cache gets invalidated with different -a|--autoload-file CLI…
Browse files Browse the repository at this point in the history
… option passed
  • Loading branch information
ondrejmirtes committed Apr 18, 2020
1 parent 3aa9a2d commit 37c29d5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 4 deletions.
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ parametersSchema:
composerAutoloaderProjectPaths: listOf(string())
analysedPathsFromConfig: listOf(string())
usedLevel: string()
cliAutoloadFile: schema(string(), nullable())

services:
-
Expand Down Expand Up @@ -339,6 +340,7 @@ services:
composerAutoloaderProjectPaths: %composerAutoloaderProjectPaths%
stubFiles: %stubFiles%
usedLevel: %usedLevel%
cliAutoloadFile: %cliAutoloadFile%

-
class: PHPStan\Cache\Cache
Expand Down
9 changes: 8 additions & 1 deletion src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@ class ResultCacheManager
/** @var string */
private $usedLevel;

/** @var string|null */
private $cliAutoloadFile;

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

Expand All @@ -42,14 +45,16 @@ class ResultCacheManager
* @param string[] $composerAutoloaderProjectPaths
* @param string[] $stubFiles
* @param string $usedLevel
* @param string|null $cliAutoloadFile
*/
public function __construct(
string $cacheFilePath,
array $allCustomConfigFiles,
array $analysedPaths,
array $composerAutoloaderProjectPaths,
array $stubFiles,
string $usedLevel
string $usedLevel,
?string $cliAutoloadFile
)
{
$this->cacheFilePath = $cacheFilePath;
Expand All @@ -58,6 +63,7 @@ public function __construct(
$this->composerAutoloaderProjectPaths = $composerAutoloaderProjectPaths;
$this->stubFiles = $stubFiles;
$this->usedLevel = $usedLevel;
$this->cliAutoloadFile = $cliAutoloadFile;
}

/**
Expand Down Expand Up @@ -366,6 +372,7 @@ private function getMeta(): array
'configFiles' => $this->getConfigFiles(),
'analysedPaths' => $this->analysedPaths,
'composerLocks' => $this->getComposerLocks(),
'cliAutoloadFile' => $this->cliAutoloadFile,
'phpExtensions' => $extensions,
'stubFiles' => $this->getStubFiles(),
'level' => $this->usedLevel,
Expand Down
5 changes: 3 additions & 2 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -76,14 +76,15 @@ public static function begin(
$currentWorkingDirectoryFileHelper = new FileHelper($currentWorkingDirectory);
$currentWorkingDirectory = $currentWorkingDirectoryFileHelper->getWorkingDirectory();
if ($autoloadFile !== null) {
$autoloadFile = $currentWorkingDirectoryFileHelper->absolutizePath($autoloadFile);
if (!is_file($autoloadFile)) {
$errorOutput->writeLineFormatted(sprintf('Autoload file "%s" not found.', $autoloadFile));
throw new \PHPStan\Command\InceptionNotSuccessfulException();
}

(static function (string $file): void {
require_once $file;
})($currentWorkingDirectoryFileHelper->absolutizePath($autoloadFile));
})($autoloadFile);
}
if ($projectConfigFile === null) {
foreach (['phpstan.neon', 'phpstan.neon.dist'] as $discoverableConfigName) {
Expand Down Expand Up @@ -240,7 +241,7 @@ public static function begin(
}

try {
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $allCustomConfigFiles, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile);
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $allCustomConfigFiles, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile);
} catch (\Nette\DI\InvalidConfigurationException | \Nette\Utils\AssertionException $e) {
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted($e->getMessage());
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public function __construct(string $currentWorkingDirectory)
* @param string[] $allCustomConfigFiles
* @param string $usedLevel
* @param string|null $generateBaselineFile
* @param string|null $cliAutoloadFile
* @return \PHPStan\DependencyInjection\Container
*/
public function create(
Expand All @@ -59,7 +60,8 @@ public function create(
array $analysedPathsFromConfig = [],
array $allCustomConfigFiles = [],
string $usedLevel = CommandHelper::DEFAULT_LEVEL,
?string $generateBaselineFile = null
?string $generateBaselineFile = null,
?string $cliAutoloadFile = null
): Container
{
$configurator = new Configurator(new LoaderFactory(
Expand All @@ -85,6 +87,7 @@ public function create(
'analysedPathsFromConfig' => $analysedPathsFromConfig,
'allCustomConfigFiles' => $allCustomConfigFiles,
'usedLevel' => $usedLevel,
'cliAutoloadFile' => $cliAutoloadFile,
]);
$configurator->addConfig($this->configDirectory . '/config.neon');
foreach ($additionalConfigFiles as $additionalConfigFile) {
Expand Down

0 comments on commit 37c29d5

Please sign in to comment.