Skip to content
Closed
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
12 changes: 6 additions & 6 deletions src/Analyser/ArgumentsHandler.php
Original file line number Diff line number Diff line change
Expand Up @@ -194,7 +194,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 @@ -206,19 +208,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();
});

$argResults = [];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,9 @@ public function resolve(
?Type $nativePassedToType,
): ClosureParameterTypes
{
/** @var Node\Arg[]|null $arrayMapArgs */
$arrayMapArgs = $expr->getAttribute(ArrayMapArgVisitor::ATTRIBUTE_NAME);
/** @var Node\Arg[]|null $immediatelyInvokedArgs */
$immediatelyInvokedArgs = $expr->getAttribute(ImmediatelyInvokedClosureVisitor::ARGS_ATTRIBUTE_NAME);

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I feel like this would be better addressed with a dynamic return type extension for getAttribute / getAttributes dynamic return type extension. We could even implement a new extension interface to be implemented alongside NodeVisitor for current rich parser visitors, to inform the extension.

$intrinsicArgs = $arrayMapArgs ?? $immediatelyInvokedArgs;
if ($intrinsicArgs === null) {
Expand Down
14 changes: 14 additions & 0 deletions src/Analyser/ResultCache/ResultCacheManager.php
Original file line number Diff line number Diff line change
Expand Up @@ -1251,6 +1251,20 @@ 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 ValueDependencies|null $valueDependencies
* @param array<string, array<string>>|null $packageDependencies

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This certainly isn't needed with the new feature that analyses closures based on each usage. Feel free to test this with dumpType inside the closure.

* @param array<string, array<RootExportedNode>> $exportedNodes
* @param array<string, array{string, bool, string}> $projectExtensionFiles
* @param array<string, CollectedDataRuleResult> $collectedDataRuleResults
*/
$doSave = function (array $errorsByFile, $locallyIgnoredErrorsByFile, $linesToIgnore, $unmatchedLineIgnores, $collectedDataByFile, ?array $dependencies, ?array $usedTraitDependencies, ?array $valueDependencies, ?array $packageDependencies, array $exportedNodes, CachedExportedNodes $cachedExportedNodes, array $projectExtensionFiles, array $collectedDataRuleResults) 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 @@ -75,7 +75,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 @@ -30,6 +30,7 @@
use PHPStan\Internal\ComposerHelper;
use PHPStan\Internal\DirectoryCreator;
use PHPStan\Internal\DirectoryCreatorException;
use PHPStan\Parser\PathRoutingParser;
use PHPStan\Process\ForkedChildCrashReporter;
use PHPStan\Process\Restart\RestartExtensionRegistry;
use PHPStan\Process\Restart\RestartManager;
Expand Down Expand Up @@ -593,6 +594,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.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ public static function __set_state(array $properties): self;

/**
* @param mixed[] $data
* @return static
*/
public static function decode(array $data, ExportedNodeDecoder $decoder): self;

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 @@ -159,6 +159,7 @@ public static function decode(array $data, ExportedNodeDecoder $decoder): self
return ExportedTraitUseAdaptation::decode($traitUseAdaptationData['data'], $decoder);
}, $data['traitUseAdaptations']),
array_map(static function (array $node) use ($decoder): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data'], $decoder);
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 @@ -122,6 +122,7 @@ public static function decode(array $data, ExportedNodeDecoder $decoder): self
$data['phpDoc'] !== null ? ExportedPhpDocNode::decode($data['phpDoc']['data'], $decoder) : null,
$data['implements'],
array_map(static function (array $node) use ($decoder): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data'], $decoder);
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 @@ -97,6 +97,7 @@ public static function decode(array $data, ExportedNodeDecoder $decoder): self
$data['phpDoc'] !== null ? ExportedPhpDocNode::decode($data['phpDoc']['data'], $decoder) : null,
$data['extends'],
array_map(static function (array $node) use ($decoder): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data'], $decoder);
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 @@ -138,6 +138,7 @@ public static function decode(array $data, ExportedNodeDecoder $decoder): self
return ExportedTraitUseAdaptation::decode($traitUseAdaptationData['data'], $decoder);
}, $data['traitUseAdaptations']),
array_map(static function (array $node) use ($decoder): ExportedNode {
/** @var class-string<ExportedNode> $nodeType */
$nodeType = $node['type'];

return $nodeType::decode($node['data'], $decoder);
Expand Down
1 change: 1 addition & 0 deletions src/DependencyInjection/NeonAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,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 @@ -381,6 +381,7 @@ public function analyse(
}
$decoder = new ExportedNodeDecoder();
$exportedNodes[$file] = array_map(static function (array $node) use ($decoder): RootExportedNode {
/** @var class-string<RootExportedNode> $class */
$class = $node['type'];

return $class::decode($node['data'], $decoder);
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 @@ -204,6 +204,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 @@ -111,6 +111,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 @@ -159,7 +160,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 @@ -424,6 +424,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, array{string, bool}> $filesWithHashes
*/
[$nameScopeMap, $filesWithHashes] = $cached;
Expand Down
3 changes: 3 additions & 0 deletions src/Type/UnionType.php
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,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