Skip to content

Commit

Permalink
Fix PHPStan Pro reanalyse results
Browse files Browse the repository at this point in the history
  • Loading branch information
ondrejmirtes committed May 5, 2021
1 parent 8fe9e60 commit 179b213
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 11 deletions.
2 changes: 2 additions & 0 deletions conf/config.neon
Original file line number Diff line number Diff line change
Expand Up @@ -316,6 +316,7 @@ parametersSchema:

# internal - static reflection
singleReflectionFile: schema(string(), nullable())
singleReflectionInsteadOfFile: schema(string(), nullable())

rules:
- PHPStan\Rules\Debug\DumpTypeRule
Expand Down Expand Up @@ -1474,6 +1475,7 @@ services:
arguments:
reflectionProvider: @innerRuntimeReflectionProvider
patterns: %staticReflectionClassNamePatterns%
singleReflectionInsteadOfFile: %singleReflectionInsteadOfFile%
autowired: false

innerRuntimeReflectionProvider:
Expand Down
5 changes: 3 additions & 2 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,8 @@ public static function begin(
bool $allowXdebug,
bool $manageMemoryLimitFile = true,
bool $debugEnabled = false,
?string $singleReflectionFile = null
?string $singleReflectionFile = null,
?string $singleReflectionInsteadOfFile = null
): InceptionResult
{
if (!$allowXdebug) {
Expand Down Expand Up @@ -249,7 +250,7 @@ public static function begin(
}

try {
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile);
$container = $containerFactory->create($tmpDir, $additionalConfigFiles, $paths, $composerAutoloaderProjectPaths, $analysedPathsFromConfig, $level ?? self::DEFAULT_LEVEL, $generateBaselineFile, $autoloadFile, $singleReflectionFile, $singleReflectionInsteadOfFile);
} catch (\Nette\DI\InvalidConfigurationException | \Nette\Utils\AssertionException $e) {
$errorOutput->writeLineFormatted('<error>Invalid configuration:</error>');
$errorOutput->writeLineFormatted($e->getMessage());
Expand Down
3 changes: 2 additions & 1 deletion src/Command/FixerWorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,8 @@ protected function execute(InputInterface $input, OutputInterface $output): int
$allowXdebug,
false,
false,
$singleReflectionFile
$singleReflectionFile,
$insteadOfFile
);
} catch (\PHPStan\Command\InceptionNotSuccessfulException $e) {
return 1;
Expand Down
5 changes: 4 additions & 1 deletion src/DependencyInjection/ContainerFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ public function __construct(string $currentWorkingDirectory)
* @param string|null $generateBaselineFile
* @param string|null $cliAutoloadFile
* @param string|null $singleReflectionFile
* @param string|null $singleReflectionInsteadOfFile
* @return \PHPStan\DependencyInjection\Container
*/
public function create(
Expand All @@ -62,7 +63,8 @@ public function create(
string $usedLevel = CommandHelper::DEFAULT_LEVEL,
?string $generateBaselineFile = null,
?string $cliAutoloadFile = null,
?string $singleReflectionFile = null
?string $singleReflectionFile = null,
?string $singleReflectionInsteadOfFile = null
): Container
{
$configurator = new Configurator(new LoaderFactory(
Expand Down Expand Up @@ -93,6 +95,7 @@ public function create(
]);
$configurator->addDynamicParameters([
'singleReflectionFile' => $singleReflectionFile,
'singleReflectionInsteadOfFile' => $singleReflectionInsteadOfFile,
]);
$configurator->addConfig($this->configDirectory . '/config.neon');
foreach ($additionalConfigFiles as $additionalConfigFile) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class ClassBlacklistReflectionProvider implements ReflectionProvider
/** @var string[] */
private array $patterns;

private ?string $singleReflectionFile;
private ?string $singleReflectionInsteadOfFile;

/**
* @param \PHPStan\Reflection\ReflectionProvider $reflectionProvider
Expand All @@ -31,13 +31,13 @@ public function __construct(
ReflectionProvider $reflectionProvider,
PhpStormStubsSourceStubber $phpStormStubsSourceStubber,
array $patterns,
?string $singleReflectionFile
?string $singleReflectionInsteadOfFile
)
{
$this->reflectionProvider = $reflectionProvider;
$this->phpStormStubsSourceStubber = $phpStormStubsSourceStubber;
$this->patterns = $patterns;
$this->singleReflectionFile = $singleReflectionFile;
$this->singleReflectionInsteadOfFile = $singleReflectionInsteadOfFile;
}

public function hasClass(string $className): bool
Expand All @@ -52,8 +52,8 @@ public function hasClass(string $className): bool
}

$classReflection = $this->reflectionProvider->getClass($className);
if ($this->singleReflectionFile !== null) {
if ($classReflection->getFileName() === $this->singleReflectionFile) {
if ($this->singleReflectionInsteadOfFile !== null) {
if ($classReflection->getFileName() === $this->singleReflectionInsteadOfFile) {
return false;
}
}
Expand Down Expand Up @@ -133,7 +133,7 @@ public function hasFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): bool
return false;
}

if ($this->singleReflectionFile === null) {
if ($this->singleReflectionInsteadOfFile === null) {
return true;
}

Expand All @@ -142,7 +142,7 @@ public function hasFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): bool
return true;
}

return $functionReflection->getFileName() !== $this->singleReflectionFile;
return $functionReflection->getFileName() !== $this->singleReflectionInsteadOfFile;
}

public function getFunction(\PhpParser\Node\Name $nameNode, ?Scope $scope): FunctionReflection
Expand Down

0 comments on commit 179b213

Please sign in to comment.