Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions src/Analyser/ExprHandler/Helper/ClosureTypeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -801,7 +801,9 @@ private function buildParametersAndAcceptors(

$callableParameters = null;
$nativeCallableParameters = null;
/** @var Node\Arg[]|null $arrayMapArgs */
$arrayMapArgs = $expr->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME);
/** @var Node\Arg[]|null $immediatelyInvokedArgs */
$immediatelyInvokedArgs = $expr->getAttribute(ImmediatelyInvokedClosureVisitor::ARGS_ATTRIBUTE_NAME);
if ($arrayMapArgs !== null) {
$callableParameters = [];
Expand Down
12 changes: 6 additions & 6 deletions src/Analyser/NodeScopeResolver.php
Original file line number Diff line number Diff line change
Expand Up @@ -1873,7 +1873,9 @@ public function processArgs(

$processingOrder = array_keys($args);
usort($processingOrder, static function (int $a, int $b) use ($args): int {
/** @var Node\Arg|null $aOriginalArg */
$aOriginalArg = $args[$a]->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE);
/** @var Node\Arg|null $bOriginalArg */
$bOriginalArg = $args[$b]->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE);
$aValue = $aOriginalArg !== null ? $aOriginalArg->value : $args[$a]->value;
$bValue = $bOriginalArg !== null ? $bOriginalArg->value : $args[$b]->value;
Expand All @@ -1885,19 +1887,17 @@ public function processArgs(
return $aIsClosure ? 1 : -1;
}

$aOriginal = $args[$a]->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE);
$bOriginal = $args[$b]->getAttribute(ArgumentsNormalizer::ORIGINAL_ARG_ATTRIBUTE);
if ($aOriginal === null && $bOriginal === null) {
if ($aOriginalArg === null && $bOriginalArg === null) {
return $a <=> $b;
}
if ($aOriginal === null) {
if ($aOriginalArg === null) {
return 1;
}
if ($bOriginal === null) {
if ($bOriginalArg === null) {
return -1;
}

return $aOriginal->getStartTokenPos() <=> $bOriginal->getStartTokenPos();
return $aOriginalArg->getStartTokenPos() <=> $bOriginalArg->getStartTokenPos();
});

$countStableMetadataAcceptor = null;
Expand Down
12 changes: 12 additions & 0 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -856,6 +856,18 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache
$projectConfigArray = $this->getPathTransformer()->relativizeProjectConfig($projectConfigArray);
$meta['projectConfig'] = Neon::encode($projectConfigArray);
}
/**
* @param array<string, list<Error>> $errorsByFile
* @param array<string, list<Error>> $locallyIgnoredErrorsByFile
* @param array<string, LinesToIgnore> $linesToIgnore
* @param array<string, LinesToIgnore> $unmatchedLineIgnores
* @param CollectorData $collectedDataByFile
* @param array<string, array<string>>|null $dependencies
* @param array<string, array<string>>|null $usedTraitDependencies
* @param array<string, array<string>>|null $packageDependencies
* @param array<string, array<RootExportedNode>> $exportedNodes
* @param array<string, array{string, bool, string}> $projectExtensionFiles
*/
$doSave = function (array $errorsByFile, $locallyIgnoredErrorsByFile, $linesToIgnore, $unmatchedLineIgnores, $collectedDataByFile, ?array $dependencies, ?array $usedTraitDependencies, ?array $packageDependencies, array $exportedNodes, array $projectExtensionFiles) use ($internalErrors, $resultCache, $output, $onlyFiles, $meta): bool {
if ($onlyFiles) {
if ($output->isVeryVerbose()) {
Expand Down
4 changes: 3 additions & 1 deletion src/Analyser/ScopeOps.php
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,9 @@ public static function nodeKey(Expr $node, ExprPrinter $exprPrinter): string
&& (($attributes['startFilePos'] ?? null) !== null)
) {
$key .= '/*' . $attributes['startFilePos'];
foreach ($attributes[ArrayMapArgVisitor::ATTRIBUTE_NAME] as $arg) {
/** @var Node\Arg[] $arrayMapArgs */
$arrayMapArgs = $attributes[ArrayMapArgVisitor::ATTRIBUTE_NAME];
foreach ($arrayMapArgs as $arg) {
$key .= ':' . $exprPrinter->printExpr($arg->value);
}
$key .= '*/';
Expand Down
2 changes: 2 additions & 0 deletions src/Command/CommandHelper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use PHPStan\Internal\ComposerHelper;
use PHPStan\Internal\DirectoryCreator;
use PHPStan\Internal\DirectoryCreatorException;
use PHPStan\Parser\PathRoutingParser;
use PHPStan\Process\ForkedChildCrashReporter;
use PHPStan\ShouldNotHappenException;
use ReflectionClass;
Expand Down Expand Up @@ -602,6 +603,7 @@ public static function begin(
/** @var FileFinder $fileFinder */
$fileFinder = $container->getService('fileFinderAnalyse');

/** @var PathRoutingParser $pathRoutingParser */
$pathRoutingParser = $container->getService('pathRoutingParser');

/** @var string[] $configStubFiles */
Expand Down
2 changes: 2 additions & 0 deletions src/Command/WorkerCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
use PHPStan\Cache\ArenaCache;
use PHPStan\File\PathNotFoundException;
use PHPStan\Parallel\WorkerRunner;
use PHPStan\Parser\PathRoutingParser;
use PHPStan\ShouldNotHappenException;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
Expand Down Expand Up @@ -127,6 +128,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int
// routing is unused either way.)
$analysedFiles = ArenaCache::lookup('analysed-files');
if (is_array($analysedFiles)) {
/** @var PathRoutingParser $pathRoutingParser */
$pathRoutingParser = $container->getService('pathRoutingParser');
$pathRoutingParser->setAnalysedFiles($analysedFiles);
} else {
Expand Down
1 change: 1 addition & 0 deletions src/Dependency/ExportedNode/ExportedClassNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,7 @@ public static function decode(array $data): self
return ExportedTraitUseAdaptation::decode($traitUseAdaptationData['data']);
}, $data['traitUseAdaptations']),
array_map(static function (array $node): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data']);
Expand Down
1 change: 1 addition & 0 deletions src/Dependency/ExportedNode/ExportedEnumNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,7 @@ public static function decode(array $data): self
$data['phpDoc'] !== null ? ExportedPhpDocNode::decode($data['phpDoc']['data']) : null,
$data['implements'],
array_map(static function (array $node): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data']);
Expand Down
1 change: 1 addition & 0 deletions src/Dependency/ExportedNode/ExportedInterfaceNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ public static function decode(array $data): self
$data['phpDoc'] !== null ? ExportedPhpDocNode::decode($data['phpDoc']['data']) : null,
$data['extends'],
array_map(static function (array $node): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data']);
Expand Down
1 change: 1 addition & 0 deletions src/Dependency/ExportedNode/ExportedTraitNode.php
Original file line number Diff line number Diff line change
Expand Up @@ -137,6 +137,7 @@ public static function decode(array $data): self
return ExportedTraitUseAdaptation::decode($traitUseAdaptationData['data']);
}, $data['traitUseAdaptations']),
array_map(static function (array $node): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data']);
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,7 @@ public function process(array $arr, string $fileKey, string $file): array
if ($val->value === Neon::CHAIN) {
$tmp = null;
foreach ($this->process($val->attributes, $fileKeyToPass, $file) as $st) {
/** @var Statement $st */
$tmp = new Statement(
$tmp === null ? $st->getEntity() : [$tmp, ltrim(implode('::', (array) $st->getEntity()), ':')],
$st->arguments,
Expand Down
1 change: 1 addition & 0 deletions src/Parallel/ParallelAnalyser.php
Original file line number Diff line number Diff line change
Expand Up @@ -336,7 +336,7 @@
}

/**
* @var string $file

Check failure on line 339 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 339 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (7.4, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.
* @var array<mixed[]> $fileExportedNodes
*/
foreach ($json['exportedNodes'] as $file => $fileExportedNodes) {
Expand All @@ -344,9 +344,10 @@
continue;
}
$exportedNodes[$file] = array_map(static function (array $node): RootExportedNode {
/** @var class-string<RootExportedNode> $class */
$class = $node['type'];

return $class::decode($node['data']);

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.2)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.4)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.3)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan with result cache (8.5)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.4, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, ubuntu-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.3, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.5, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.0, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.2, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / PHPStan (8.1, windows-latest)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.3, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.4, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.4, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.5, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.5, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (ubuntu-latest, 8.3, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (macos-latest, 8.5, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.5, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.3, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.4, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.4, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.5, zts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Run with Turbo Extension (windows-latest, 8.3, nts, make phpstan)

Anonymous function should return PHPStan\Dependency\RootExportedNode but returns PHPStan\Dependency\ExportedNode.

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.4, ubuntu-latest)

Anonymous fu

Check failure on line 350 in src/Parallel/ParallelAnalyser.php

View workflow job for this annotation

GitHub Actions / Mutation Testing (8.3, ubuntu-latest)

Anonymous fu
}, $fileExportedNodes);
}

Expand Down
2 changes: 2 additions & 0 deletions src/PhpDoc/StubValidator.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
use PHPStan\DependencyInjection\Container;
use PHPStan\DependencyInjection\ContainerFactory;
use PHPStan\DependencyInjection\DerivativeContainerFactory;
use PHPStan\Parser\PathRoutingParser;
use PHPStan\Rules\DirectRegistry as DirectRuleRegistry;
use Throwable;
use function array_fill_keys;
Expand Down Expand Up @@ -53,6 +54,7 @@ public function validate(array $stubFiles, bool $debug): array
$nodeScopeResolver = $container->getByType(NodeScopeResolver::class);
$nodeScopeResolver->setAnalysedFiles($stubFiles);

/** @var PathRoutingParser $pathRoutingParser */
$pathRoutingParser = $container->getService('pathRoutingParser');
$pathRoutingParser->setAnalysedFiles($stubFiles);

Expand Down
1 change: 1 addition & 0 deletions src/Reflection/ParametersAcceptorSelector.php
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ public static function applyIntrinsicArgOverrides(
count($args) > 0
&& count($parametersAcceptors) > 0
) {
/** @var Node\Arg[]|null $arrayMapArgs */
$arrayMapArgs = $args[0]->value->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME);
if ($arrayMapArgs !== null) {
$callbackParameters = [];
Expand Down
1 change: 1 addition & 0 deletions src/Rules/Debug/FileAssertRule.php
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ private function processAssertVariableCertainty(array $args, Scope $scope): arra
];
}

/** @var TrinaryLogic $expectedCertaintyValue */
// @phpstan-ignore staticMethod.dynamicName
$expectedCertaintyValue = TrinaryLogic::{$certainty->name->toString()}();
$variable = $args[1]->value;
Expand Down
4 changes: 4 additions & 0 deletions src/Testing/PHPUnit/ContainerInitializer.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,14 @@
namespace PHPStan\Testing\PHPUnit;

use PHPStan\DependencyInjection\InvalidIgnoredErrorExceptionTest;
use PHPStan\Testing\PHPStanTestCase;

final class ContainerInitializer
{

/**
* @param class-string<PHPStanTestCase> $testClassName
*/
public static function initialize(string $testClassName): void
{
// This test expects an exception during container initialization
Expand Down
3 changes: 3 additions & 0 deletions src/Testing/TypeInferenceTestCase.php
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,7 @@ public function assertFileAsserts(
$expectedType = $args[0];
$this->assertInstanceOf(ConstantScalarType::class, $expectedType);
$expected = $expectedType->getValue();
/** @var Type $actualType */
$actualType = $args[1];
$actual = $actualType->describe(VerbosityLevel::precise());
} else {
Expand Down Expand Up @@ -182,7 +183,9 @@ public function assertFileAsserts(
$failureMessage,
);
} elseif ($assertType === 'variableCertainty') {
/** @var TrinaryLogic $expectedCertainty */
$expectedCertainty = $args[0];
/** @var TrinaryLogic $actualCertainty */
$actualCertainty = $args[1];
$variableName = $args[2];

Expand Down
1 change: 1 addition & 0 deletions src/Type/FileTypeMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -377,6 +377,7 @@ private function loadCachedPhpDocNodeMap(string $cacheKey, string $variableCache
$cached = $this->cache->load($cacheKey, $variableCacheKey);
if ($cached !== null) {
/**
* @var array<string, IntermediaryNameScope> $nameScopeMap
* @var array<string, string> $filesWithHashes
*/
[$nameScopeMap, $filesWithHashes] = $cached;
Expand Down
1 change: 1 addition & 0 deletions src/Type/Regex/RegexGroupParser.php
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@ private function createEmptyTokenTreeNode(TreeNode $parentAst): TreeNode

private function updateAlternationAstRemoveVerticalBarsAndAddEmptyToken(TreeNode $ast): void
{
/** @var TreeNode[] $children */
$children = $ast->getChildren();

foreach ($children as $i => $child) {
Expand Down
3 changes: 3 additions & 0 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,9 @@ public function describe(VerbosityLevel $level): string
if (isset($this->cachedDescriptions[$level->getLevelValue()])) {
return $this->cachedDescriptions[$level->getLevelValue()];
}
/**
* @param Type[] $types
*/
$joinTypes = static function (array $types) use ($level): string {
$typeNames = [];
foreach ($types as $i => $type) {
Expand Down
Loading