From 79ddfced3906ef5e205476d39210ceca277435d5 Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 11 Feb 2026 12:42:01 +0000 Subject: [PATCH] Use named arguments for unreadable calls --- src/Analyser/Analyser.php | 26 +-- src/Analyser/AnalyserResultFinalizer.php | 80 +++---- src/Analyser/ConstantResolver.php | 2 +- src/Analyser/ExpressionContext.php | 4 +- .../Ignore/IgnoredErrorHelperResult.php | 8 +- src/Analyser/InternalThrowPoint.php | 2 +- src/Analyser/MutatingScope.php | 4 +- src/Analyser/NodeScopeResolver.php | 14 +- .../ResultCache/ResultCacheManager.php | 196 ++++++++++++++++-- src/Analyser/ScopeContext.php | 6 +- src/Analyser/ThrowPoint.php | 2 +- src/Command/AnalyseApplication.php | 68 +++--- src/Command/AnalyseCommand.php | 6 +- src/Command/AnalyserRunner.php | 16 +- src/Command/FixerApplication.php | 2 +- src/Command/FixerWorkerCommand.php | 24 ++- src/Command/IgnoredRegexValidator.php | 12 +- src/Command/WorkerCommand.php | 4 +- .../ExportedTraitUseAdaptation.php | 4 +- .../ValidateIgnoredErrorsExtension.php | 2 +- src/Parallel/ParallelAnalyser.php | 38 ++-- src/PhpDoc/PhpDocNodeResolver.php | 12 +- src/PhpDoc/StubValidator.php | 8 +- src/PhpDoc/TypeNodeResolver.php | 2 +- src/Reflection/Callables/SimpleThrowPoint.php | 2 +- src/Reflection/InitializerExprContext.php | 10 +- src/Reflection/ParametersAcceptorSelector.php | 28 +-- .../Php/ClosureCallMethodReflection.php | 10 +- src/Testing/PHPStanTestCase.php | 2 +- src/Type/CallableType.php | 8 +- src/Type/ClosureType.php | 20 +- src/Type/TypeUtils.php | 2 +- 32 files changed, 417 insertions(+), 207 deletions(-) diff --git a/src/Analyser/Analyser.php b/src/Analyser/Analyser.php index 00408bb0af2..b4928e66550 100644 --- a/src/Analyser/Analyser.php +++ b/src/Analyser/Analyser.php @@ -130,19 +130,19 @@ public function analyse( } return new AnalyserResult( - $errors, - $filteredPhpErrors, - $allPhpErrors, - $locallyIgnoredErrors, - $linesToIgnore, - $unmatchedLineIgnores, - [], - $collectedData, - $internalErrorsCount === 0 ? $dependencies : null, - $internalErrorsCount === 0 ? $usedTraitDependencies : null, - $exportedNodes, - $reachedInternalErrorsCountLimit, - memory_get_peak_usage(true), + unorderedErrors: $errors, + filteredPhpErrors: $filteredPhpErrors, + allPhpErrors: $allPhpErrors, + locallyIgnoredErrors: $locallyIgnoredErrors, + linesToIgnore: $linesToIgnore, + unmatchedLineIgnores: $unmatchedLineIgnores, + internalErrors: [], + collectedData: $collectedData, + dependencies: $internalErrorsCount === 0 ? $dependencies : null, + usedTraitDependencies: $internalErrorsCount === 0 ? $usedTraitDependencies : null, + exportedNodes: $exportedNodes, + reachedInternalErrorsCountLimit: $reachedInternalErrorsCountLimit, + peakMemoryUsageBytes: memory_get_peak_usage(true), ); } diff --git a/src/Analyser/AnalyserResultFinalizer.php b/src/Analyser/AnalyserResultFinalizer.php index 97c3bdfd1c3..6c3ab6b2c26 100644 --- a/src/Analyser/AnalyserResultFinalizer.php +++ b/src/Analyser/AnalyserResultFinalizer.php @@ -87,7 +87,7 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $ sprintf('running CollectedDataNode rule %s', get_class($rule)), InternalError::prepareTrace($t), $t->getTraceAsString(), - true, + shouldReportBug: true, ); continue; } @@ -135,38 +135,38 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $ } return $this->addUnmatchedIgnoredErrors(new AnalyserResult( - array_merge($errors, $analyserResult->getFilteredPhpErrors()), - [], - $analyserResult->getAllPhpErrors(), - $locallyIgnoredErrors, - $allLinesToIgnore, - $allUnmatchedLineIgnores, - $internalErrors, - $analyserResult->getCollectedData(), - $analyserResult->getDependencies(), - $analyserResult->getUsedTraitDependencies(), - $analyserResult->getExportedNodes(), - $analyserResult->hasReachedInternalErrorsCountLimit(), - $analyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: array_merge($errors, $analyserResult->getFilteredPhpErrors()), + filteredPhpErrors: [], + allPhpErrors: $analyserResult->getAllPhpErrors(), + locallyIgnoredErrors: $locallyIgnoredErrors, + linesToIgnore: $allLinesToIgnore, + unmatchedLineIgnores: $allUnmatchedLineIgnores, + internalErrors: $internalErrors, + collectedData: $analyserResult->getCollectedData(), + dependencies: $analyserResult->getDependencies(), + usedTraitDependencies: $analyserResult->getUsedTraitDependencies(), + exportedNodes: $analyserResult->getExportedNodes(), + reachedInternalErrorsCountLimit: $analyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $analyserResult->getPeakMemoryUsageBytes(), ), $collectorErrors, $locallyIgnoredCollectorErrors); } private function mergeFilteredPhpErrors(AnalyserResult $analyserResult): AnalyserResult { return new AnalyserResult( - array_merge($analyserResult->getUnorderedErrors(), $analyserResult->getFilteredPhpErrors()), - [], - $analyserResult->getAllPhpErrors(), - $analyserResult->getLocallyIgnoredErrors(), - $analyserResult->getLinesToIgnore(), - $analyserResult->getUnmatchedLineIgnores(), - $analyserResult->getInternalErrors(), - $analyserResult->getCollectedData(), - $analyserResult->getDependencies(), - $analyserResult->getUsedTraitDependencies(), - $analyserResult->getExportedNodes(), - $analyserResult->hasReachedInternalErrorsCountLimit(), - $analyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: array_merge($analyserResult->getUnorderedErrors(), $analyserResult->getFilteredPhpErrors()), + filteredPhpErrors: [], + allPhpErrors: $analyserResult->getAllPhpErrors(), + locallyIgnoredErrors: $analyserResult->getLocallyIgnoredErrors(), + linesToIgnore: $analyserResult->getLinesToIgnore(), + unmatchedLineIgnores: $analyserResult->getUnmatchedLineIgnores(), + internalErrors: $analyserResult->getInternalErrors(), + collectedData: $analyserResult->getCollectedData(), + dependencies: $analyserResult->getDependencies(), + usedTraitDependencies: $analyserResult->getUsedTraitDependencies(), + exportedNodes: $analyserResult->getExportedNodes(), + reachedInternalErrorsCountLimit: $analyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $analyserResult->getPeakMemoryUsageBytes(), ); } @@ -218,19 +218,19 @@ private function addUnmatchedIgnoredErrors( return new FinalizerResult( new AnalyserResult( - $errors, - $analyserResult->getFilteredPhpErrors(), - $analyserResult->getAllPhpErrors(), - $analyserResult->getLocallyIgnoredErrors(), - $analyserResult->getLinesToIgnore(), - $analyserResult->getUnmatchedLineIgnores(), - $analyserResult->getInternalErrors(), - $analyserResult->getCollectedData(), - $analyserResult->getDependencies(), - $analyserResult->getUsedTraitDependencies(), - $analyserResult->getExportedNodes(), - $analyserResult->hasReachedInternalErrorsCountLimit(), - $analyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: $errors, + filteredPhpErrors: $analyserResult->getFilteredPhpErrors(), + allPhpErrors: $analyserResult->getAllPhpErrors(), + locallyIgnoredErrors: $analyserResult->getLocallyIgnoredErrors(), + linesToIgnore: $analyserResult->getLinesToIgnore(), + unmatchedLineIgnores: $analyserResult->getUnmatchedLineIgnores(), + internalErrors: $analyserResult->getInternalErrors(), + collectedData: $analyserResult->getCollectedData(), + dependencies: $analyserResult->getDependencies(), + usedTraitDependencies: $analyserResult->getUsedTraitDependencies(), + exportedNodes: $analyserResult->getExportedNodes(), + reachedInternalErrorsCountLimit: $analyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $analyserResult->getPeakMemoryUsageBytes(), ), $collectorErrors, $locallyIgnoredCollectorErrors, diff --git a/src/Analyser/ConstantResolver.php b/src/Analyser/ConstantResolver.php index 6d712a165b9..368f01a0986 100644 --- a/src/Analyser/ConstantResolver.php +++ b/src/Analyser/ConstantResolver.php @@ -419,7 +419,7 @@ public function resolveConstantType(string $constantName, Type $constantType): T $phpdocTypes = $this->dynamicConstantNames[$constantName]; if ($this->container !== null) { $typeStringResolver = $this->container->getByType(TypeStringResolver::class); - return $typeStringResolver->resolve($phpdocTypes, new NameScope(null, [], null)); + return $typeStringResolver->resolve($phpdocTypes, new NameScope(null, [], className: null)); } return $constantType; } diff --git a/src/Analyser/ExpressionContext.php b/src/Analyser/ExpressionContext.php index 1092a7282c3..ad0d16618ee 100644 --- a/src/Analyser/ExpressionContext.php +++ b/src/Analyser/ExpressionContext.php @@ -17,12 +17,12 @@ private function __construct( public static function createTopLevel(): self { - return new self(false, null, null); + return new self(isDeep: false, inAssignRightSideVariableName: null, inAssignRightSideExpr: null); } public static function createDeep(): self { - return new self(true, null, null); + return new self(isDeep: true, inAssignRightSideVariableName: null, inAssignRightSideExpr: null); } public function enterDeep(): self diff --git a/src/Analyser/Ignore/IgnoredErrorHelperResult.php b/src/Analyser/Ignore/IgnoredErrorHelperResult.php index 6490999b803..d1e04009a54 100644 --- a/src/Analyser/Ignore/IgnoredErrorHelperResult.php +++ b/src/Analyser/Ignore/IgnoredErrorHelperResult.php @@ -58,13 +58,13 @@ public function process( $processIgnoreError = function (Error $error, int $i, $ignore) use (&$unmatchedIgnoredErrors, &$stringErrors): bool { $shouldBeIgnored = false; if (is_string($ignore)) { - $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, $ignore, null, null, null); + $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, ignoredErrorPattern: $ignore, ignoredErrorMessage: null, identifier: null, path: null); if ($shouldBeIgnored) { unset($unmatchedIgnoredErrors[$i]); } } else { if (isset($ignore['path'])) { - $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, $ignore['message'] ?? null, $ignore['rawMessage'] ?? null, $ignore['identifier'] ?? null, $ignore['path']); + $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, ignoredErrorPattern: $ignore['message'] ?? null, ignoredErrorMessage: $ignore['rawMessage'] ?? null, identifier: $ignore['identifier'] ?? null, path: $ignore['path']); if ($shouldBeIgnored) { if (isset($ignore['count'])) { $realCount = $unmatchedIgnoredErrors[$i]['realCount'] ?? 0; @@ -85,7 +85,7 @@ public function process( } } elseif (isset($ignore['paths'])) { foreach ($ignore['paths'] as $j => $ignorePath) { - $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, $ignore['message'] ?? null, $ignore['rawMessage'] ?? null, $ignore['identifier'] ?? null, $ignorePath); + $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, ignoredErrorPattern: $ignore['message'] ?? null, ignoredErrorMessage: $ignore['rawMessage'] ?? null, identifier: $ignore['identifier'] ?? null, path: $ignorePath); if (!$shouldBeIgnored) { continue; } @@ -102,7 +102,7 @@ public function process( break; } } else { - $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, $ignore['message'] ?? null, $ignore['rawMessage'] ?? null, $ignore['identifier'] ?? null, null); + $shouldBeIgnored = IgnoredError::shouldIgnore($this->fileHelper, $error, ignoredErrorPattern: $ignore['message'] ?? null, ignoredErrorMessage: $ignore['rawMessage'] ?? null, identifier: $ignore['identifier'] ?? null, path: null); if ($shouldBeIgnored) { unset($unmatchedIgnoredErrors[$i]); } diff --git a/src/Analyser/InternalThrowPoint.php b/src/Analyser/InternalThrowPoint.php index 830a121e5cf..92291bd5acc 100644 --- a/src/Analyser/InternalThrowPoint.php +++ b/src/Analyser/InternalThrowPoint.php @@ -47,7 +47,7 @@ public static function createExplicit(MutatingScope $scope, Type $type, Node $no */ public static function createImplicit(MutatingScope $scope, Node $node): self { - return new self($scope, new ObjectType(Throwable::class), $node, false, true); + return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true); } public static function createFromPublic(ThrowPoint $throwPoint): self diff --git a/src/Analyser/MutatingScope.php b/src/Analyser/MutatingScope.php index 2744d23ab72..6be5088a392 100644 --- a/src/Analyser/MutatingScope.php +++ b/src/Analyser/MutatingScope.php @@ -5611,11 +5611,11 @@ private function getClosureType(Expr\Closure|Expr\ArrowFunction $node): ClosureT if ($arrayMapArgs !== null) { $callableParameters = []; foreach ($arrayMapArgs as $funcCallArg) { - $callableParameters[] = new DummyParameter('item', $this->getType($funcCallArg->value)->getIterableValueType(), false, PassedByReference::createNo(), false, null); + $callableParameters[] = new DummyParameter('item', $this->getType($funcCallArg->value)->getIterableValueType(), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null); } } elseif ($immediatelyInvokedArgs !== null) { foreach ($immediatelyInvokedArgs as $immediatelyInvokedArg) { - $callableParameters[] = new DummyParameter('item', $this->getType($immediatelyInvokedArg->value), false, PassedByReference::createNo(), false, null); + $callableParameters[] = new DummyParameter('item', $this->getType($immediatelyInvokedArg->value), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null); } } else { $inFunctionCallsStackCount = count($this->inFunctionCallsStack); diff --git a/src/Analyser/NodeScopeResolver.php b/src/Analyser/NodeScopeResolver.php index 4c62a3c9acc..fee23f509e6 100644 --- a/src/Analyser/NodeScopeResolver.php +++ b/src/Analyser/NodeScopeResolver.php @@ -569,12 +569,12 @@ private function processStmtNode( ) { $methodReflection = $scope->getClassReflection()->getNativeMethod($stmt->name->toString()); if ($methodReflection instanceof NativeMethodReflection) { - return new InternalStatementResult($scope, false, false, [], [], []); + return new InternalStatementResult($scope, hasYield: false, isAlwaysTerminating: false, exitPoints: [], throwPoints: [], impurePoints: []); } if ($methodReflection instanceof PhpMethodReflection) { $declaringTrait = $methodReflection->getDeclaringTrait(); if ($declaringTrait === null || $declaringTrait->getName() !== $scope->getTraitReflection()->getName()) { - return new InternalStatementResult($scope, false, false, [], [], []); + return new InternalStatementResult($scope, hasYield: false, isAlwaysTerminating: false, exitPoints: [], throwPoints: [], impurePoints: []); } } } @@ -1013,10 +1013,10 @@ private function processStmtNode( $throwPoints = []; $impurePoints = []; } elseif ($stmt instanceof Node\Stmt\Trait_) { - return new InternalStatementResult($scope, false, false, [], [], []); + return new InternalStatementResult($scope, hasYield: false, isAlwaysTerminating: false, exitPoints: [], throwPoints: [], impurePoints: []); } elseif ($stmt instanceof Node\Stmt\ClassLike) { if (!$context->isTopLevel()) { - return new InternalStatementResult($scope, false, false, [], [], []); + return new InternalStatementResult($scope, hasYield: false, isAlwaysTerminating: false, exitPoints: [], throwPoints: [], impurePoints: []); } $hasYield = false; $throwPoints = []; @@ -3889,7 +3889,7 @@ function (MutatingScope $scope) use ($stmt, $expr, $nodeCallback, $context, $sto } } elseif ($expr instanceof List_) { // only in assign and foreach, processed elsewhere - return new ExpressionResult($scope, false, false, [], []); + return new ExpressionResult($scope, hasYield: false, isAlwaysTerminating: false, throwPoints: [], impurePoints: []); } elseif ($expr instanceof New_) { $parametersAcceptor = null; $constructorReflection = null; @@ -6445,7 +6445,7 @@ private function processAssignVar( new GetOffsetValueTypeExpr($assignedExpr, $dimExpr), $nodeCallback, $context, - static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []), + static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, hasYield: false, isAlwaysTerminating: false, throwPoints: [], impurePoints: []), $enterExpressionAssign, ); $scope = $result->getScope(); @@ -6553,7 +6553,7 @@ private function processVirtualAssign(MutatingScope $scope, ExpressionResultStor $assignedExpr, new VirtualAssignNodeCallback($nodeCallback), ExpressionContext::createDeep(), - static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, false, false, [], []), + static fn (MutatingScope $scope): ExpressionResult => new ExpressionResult($scope, hasYield: false, isAlwaysTerminating: false, throwPoints: [], impurePoints: []), false, ); } diff --git a/src/Analyser/ResultCache/ResultCacheManager.php b/src/Analyser/ResultCache/ResultCacheManager.php index b987237140f..3b929cc59ee 100644 --- a/src/Analyser/ResultCache/ResultCacheManager.php +++ b/src/Analyser/ResultCache/ResultCacheManager.php @@ -133,13 +133,43 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? if ($output->isVeryVerbose()) { $output->writeLineFormatted('Result cache not used because of debug mode.'); } - return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $this->getMeta($allAnalysedFiles, $projectConfigArray), + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } if ($onlyFiles) { if ($output->isVeryVerbose()) { $output->writeLineFormatted('Result cache not used because only files were passed as analysed paths.'); } - return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $this->getMeta($allAnalysedFiles, $projectConfigArray), + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } $cacheFilePath = $this->cacheFilePath; @@ -147,7 +177,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? if ($output->isVeryVerbose()) { $output->writeLineFormatted('Result cache not used because the cache file does not exist.'); } - return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $this->getMeta($allAnalysedFiles, $projectConfigArray), + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } try { @@ -159,7 +204,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? @unlink($cacheFilePath); - return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $this->getMeta($allAnalysedFiles, $projectConfigArray), + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } if (!is_array($data)) { @@ -168,7 +228,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? $output->writeLineFormatted('Result cache not used because the cache file is corrupted.'); } - return new ResultCache($allAnalysedFiles, true, time(), $this->getMeta($allAnalysedFiles, $projectConfigArray), [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $this->getMeta($allAnalysedFiles, $projectConfigArray), + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } $meta = $this->getMeta($allAnalysedFiles, $projectConfigArray); @@ -177,7 +252,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? $diffs = $this->getMetaKeyDifferences($data['meta'], $meta); $output->writeLineFormatted('Result cache not used because the metadata do not match: ' . implode(', ', $diffs)); } - return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $meta, + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } $daysOldForSkip = $this->skipResultCacheIfOlderThanDays; @@ -187,7 +277,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? } // run full analysis if the result cache is older than X days - return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $meta, + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } /** @@ -202,7 +307,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? if ($output->isVeryVerbose()) { $output->writeLineFormatted(sprintf('Result cache not used because extension file %s was not found.', $extensionFile)); } - return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $meta, + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } if ($this->getFileHash($extensionFile) === $fileHash) { @@ -213,7 +333,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? $output->writeLineFormatted(sprintf('Result cache not used because extension file %s hash does not match.', $extensionFile)); } - return new ResultCache($allAnalysedFiles, true, time(), $meta, [], [], [], [], [], [], [], [], [], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $allAnalysedFiles, + fullAnalysis: true, + lastFullAnalysisTime: time(), + meta: $meta, + errors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + projectExtensionFiles: [], + currentFileHashes: $currentFileHashes, + ); } $invertedDependencies = $data['dependencies']; @@ -365,7 +500,22 @@ public function restore(array $allAnalysedFiles, bool $debug, bool $onlyFiles, ? )); } - return new ResultCache($filesToAnalyse, false, $data['lastFullAnalysisTime'], $meta, $filteredErrors, $filteredLocallyIgnoredErrors, $filteredLinesToIgnore, $filteredUnmatchedLineIgnores, $filteredCollectedData, $invertedDependenciesToReturn, $invertedUsedTraitDependenciesToReturn, $filteredExportedNodes, $data['projectExtensionFiles'], $currentFileHashes); + return new ResultCache( + filesToAnalyse: $filesToAnalyse, + fullAnalysis: false, + lastFullAnalysisTime: $data['lastFullAnalysisTime'], + meta: $meta, + errors: $filteredErrors, + locallyIgnoredErrors: $filteredLocallyIgnoredErrors, + linesToIgnore: $filteredLinesToIgnore, + unmatchedLineIgnores: $filteredUnmatchedLineIgnores, + collectedData: $filteredCollectedData, + dependencies: $invertedDependenciesToReturn, + usedTraitDependencies: $invertedUsedTraitDependenciesToReturn, + exportedNodes: $filteredExportedNodes, + projectExtensionFiles: $data['projectExtensionFiles'], + currentFileHashes: $currentFileHashes, + ); } /** @@ -597,19 +747,19 @@ public function process(AnalyserResult $analyserResult, ResultCache $resultCache } return new ResultCacheProcessResult(new AnalyserResult( - $flatErrors, - $analyserResult->getFilteredPhpErrors(), - $analyserResult->getAllPhpErrors(), - $flatLocallyIgnoredErrors, - $linesToIgnore, - $unmatchedLineIgnores, - $internalErrors, - $collectedDataByFile, - $dependencies, - $usedTraitDependencies, - $exportedNodes, - $analyserResult->hasReachedInternalErrorsCountLimit(), - $analyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: $flatErrors, + filteredPhpErrors: $analyserResult->getFilteredPhpErrors(), + allPhpErrors: $analyserResult->getAllPhpErrors(), + locallyIgnoredErrors: $flatLocallyIgnoredErrors, + linesToIgnore: $linesToIgnore, + unmatchedLineIgnores: $unmatchedLineIgnores, + internalErrors: $internalErrors, + collectedData: $collectedDataByFile, + dependencies: $dependencies, + usedTraitDependencies: $usedTraitDependencies, + exportedNodes: $exportedNodes, + reachedInternalErrorsCountLimit: $analyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $analyserResult->getPeakMemoryUsageBytes(), ), $saved); } diff --git a/src/Analyser/ScopeContext.php b/src/Analyser/ScopeContext.php index dfa0c1f17bb..fd236256111 100644 --- a/src/Analyser/ScopeContext.php +++ b/src/Analyser/ScopeContext.php @@ -19,12 +19,12 @@ private function __construct( /** @api */ public static function create(string $file): self { - return new self($file, null, null); + return new self($file, classReflection: null, traitReflection: null); } public function beginFile(): self { - return new self($this->file, null, null); + return new self($this->file, classReflection: null, traitReflection: null); } public function enterClass(ClassReflection $classReflection): self @@ -35,7 +35,7 @@ public function enterClass(ClassReflection $classReflection): self if ($classReflection->isTrait()) { throw new ShouldNotHappenException(); } - return new self($this->file, $classReflection, null); + return new self($this->file, $classReflection, traitReflection: null); } public function enterTrait(ClassReflection $traitReflection): self diff --git a/src/Analyser/ThrowPoint.php b/src/Analyser/ThrowPoint.php index a0ba87221a7..a3a2a4808a7 100644 --- a/src/Analyser/ThrowPoint.php +++ b/src/Analyser/ThrowPoint.php @@ -40,7 +40,7 @@ public static function createExplicit(Scope $scope, Type $type, Node $node, bool */ public static function createImplicit(Scope $scope, Node $node): self { - return new self($scope, new ObjectType(Throwable::class), $node, false, true); + return new self($scope, new ObjectType(Throwable::class), $node, explicit: false, canContainAnyThrowable: true); } public function getScope(): Scope diff --git a/src/Command/AnalyseApplication.php b/src/Command/AnalyseApplication.php index c9ce77ffd68..3b6d5842b4f 100644 --- a/src/Command/AnalyseApplication.php +++ b/src/Command/AnalyseApplication.php @@ -108,19 +108,19 @@ public function analyse( ) { $stubErrors = $this->stubValidator->validate($projectStubFiles, $debug); $intermediateAnalyserResult = new AnalyserResult( - array_merge($intermediateAnalyserResult->getUnorderedErrors(), $stubErrors), - $intermediateAnalyserResult->getFilteredPhpErrors(), - $intermediateAnalyserResult->getAllPhpErrors(), - $intermediateAnalyserResult->getLocallyIgnoredErrors(), - $intermediateAnalyserResult->getLinesToIgnore(), - $intermediateAnalyserResult->getUnmatchedLineIgnores(), - $intermediateAnalyserResult->getInternalErrors(), - $intermediateAnalyserResult->getCollectedData(), - $intermediateAnalyserResult->getDependencies(), - $intermediateAnalyserResult->getUsedTraitDependencies(), - $intermediateAnalyserResult->getExportedNodes(), - $intermediateAnalyserResult->hasReachedInternalErrorsCountLimit(), - $intermediateAnalyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: array_merge($intermediateAnalyserResult->getUnorderedErrors(), $stubErrors), + filteredPhpErrors: $intermediateAnalyserResult->getFilteredPhpErrors(), + allPhpErrors: $intermediateAnalyserResult->getAllPhpErrors(), + locallyIgnoredErrors: $intermediateAnalyserResult->getLocallyIgnoredErrors(), + linesToIgnore: $intermediateAnalyserResult->getLinesToIgnore(), + unmatchedLineIgnores: $intermediateAnalyserResult->getUnmatchedLineIgnores(), + internalErrors: $intermediateAnalyserResult->getInternalErrors(), + collectedData: $intermediateAnalyserResult->getCollectedData(), + dependencies: $intermediateAnalyserResult->getDependencies(), + usedTraitDependencies: $intermediateAnalyserResult->getUsedTraitDependencies(), + exportedNodes: $intermediateAnalyserResult->getExportedNodes(), + reachedInternalErrorsCountLimit: $intermediateAnalyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $intermediateAnalyserResult->getPeakMemoryUsageBytes(), ); } @@ -225,7 +225,21 @@ private function runAnalyser( $errorOutput->getStyle()->progressStart($allAnalysedFilesCount); $errorOutput->getStyle()->progressAdvance($allAnalysedFilesCount); $errorOutput->getStyle()->progressFinish(); - return new AnalyserResult([], [], [], [], [], [], [], [], [], [], [], false, memory_get_peak_usage(true)); + return new AnalyserResult( + unorderedErrors: [], + filteredPhpErrors: [], + allPhpErrors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + internalErrors: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + reachedInternalErrorsCountLimit: false, + peakMemoryUsageBytes: memory_get_peak_usage(true), + ); } if (!$debug) { @@ -319,19 +333,19 @@ private function switchTmpFileInAnalyserResult( } return new AnalyserResult( - $this->switchTmpFileInErrors($analyserResult->getUnorderedErrors(), $insteadOfFile, $tmpFile), - $this->switchTmpFileInErrors($analyserResult->getFilteredPhpErrors(), $insteadOfFile, $tmpFile), - $this->switchTmpFileInErrors($analyserResult->getAllPhpErrors(), $insteadOfFile, $tmpFile), - $this->switchTmpFileInErrors($analyserResult->getLocallyIgnoredErrors(), $insteadOfFile, $tmpFile), - $this->switchTmpFileInLinesToIgnore($analyserResult->getLinesToIgnore(), $insteadOfFile, $tmpFile), - $this->switchTmpFileInLinesToIgnore($analyserResult->getUnmatchedLineIgnores(), $insteadOfFile, $tmpFile), - $analyserResult->getInternalErrors(), - $newCollectedData, - $dependencies, - $usedTraitDependencies, - $exportedNodes, - $analyserResult->hasReachedInternalErrorsCountLimit(), - $analyserResult->getPeakMemoryUsageBytes(), + unorderedErrors: $this->switchTmpFileInErrors($analyserResult->getUnorderedErrors(), $insteadOfFile, $tmpFile), + filteredPhpErrors: $this->switchTmpFileInErrors($analyserResult->getFilteredPhpErrors(), $insteadOfFile, $tmpFile), + allPhpErrors: $this->switchTmpFileInErrors($analyserResult->getAllPhpErrors(), $insteadOfFile, $tmpFile), + locallyIgnoredErrors: $this->switchTmpFileInErrors($analyserResult->getLocallyIgnoredErrors(), $insteadOfFile, $tmpFile), + linesToIgnore: $this->switchTmpFileInLinesToIgnore($analyserResult->getLinesToIgnore(), $insteadOfFile, $tmpFile), + unmatchedLineIgnores: $this->switchTmpFileInLinesToIgnore($analyserResult->getUnmatchedLineIgnores(), $insteadOfFile, $tmpFile), + internalErrors: $analyserResult->getInternalErrors(), + collectedData: $newCollectedData, + dependencies: $dependencies, + usedTraitDependencies: $usedTraitDependencies, + exportedNodes: $exportedNodes, + reachedInternalErrorsCountLimit: $analyserResult->hasReachedInternalErrorsCountLimit(), + peakMemoryUsageBytes: $analyserResult->getPeakMemoryUsageBytes(), ); } diff --git a/src/Command/AnalyseCommand.php b/src/Command/AnalyseCommand.php index f14d289baf5..ee40d2b0d75 100644 --- a/src/Command/AnalyseCommand.php +++ b/src/Command/AnalyseCommand.php @@ -401,7 +401,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $internalError->getContextDescription(), $internalError->getTrace(), $internalError->getTraceAsString(), - $internalError->shouldReportBug(), + shouldReportBug: $internalError->shouldReportBug(), ), false]; } foreach ($analysisResult->getFileSpecificErrors() as $fileSpecificError) { @@ -431,7 +431,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int sprintf('analysing file %s', $fileSpecificError->getTraitFilePath() ?? $fileSpecificError->getFilePath()), $metadata[InternalError::STACK_TRACE_METADATA_KEY] ?? [], $metadata[InternalError::STACK_TRACE_AS_STRING_METADATA_KEY] ?? null, - true, + shouldReportBug: true, ), !$hasStackTrace]; } @@ -453,7 +453,7 @@ protected function execute(InputInterface $input, OutputInterface $output): int $internalError->getContextDescription(), $internalError->getTrace(), $internalError->getTraceAsString(), - $internalError->shouldReportBug(), + shouldReportBug: $internalError->shouldReportBug(), ); } diff --git a/src/Command/AnalyserRunner.php b/src/Command/AnalyserRunner.php index 7b38aee6e09..c452ba4976d 100644 --- a/src/Command/AnalyserRunner.php +++ b/src/Command/AnalyserRunner.php @@ -54,7 +54,21 @@ public function runAnalyser( { $filesCount = count($files); if ($filesCount === 0) { - return new AnalyserResult([], [], [], [], [], [], [], [], [], [], [], false, memory_get_peak_usage(true)); + return new AnalyserResult( + unorderedErrors: [], + filteredPhpErrors: [], + allPhpErrors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + internalErrors: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + reachedInternalErrorsCountLimit: false, + peakMemoryUsageBytes: memory_get_peak_usage(true), + ); } $schedule = $this->scheduler->scheduleWork($this->cpuCoreCounter->getNumberOfCpuCores(), $files); diff --git a/src/Command/FixerApplication.php b/src/Command/FixerApplication.php index 0ee0689ede1..2aca7df5f05 100644 --- a/src/Command/FixerApplication.php +++ b/src/Command/FixerApplication.php @@ -522,7 +522,7 @@ private function analyse( 'running PHPStan Pro worker', $trace, $traceAsString, - false, + shouldReportBug: false, )], ]]); }); diff --git a/src/Command/FixerWorkerCommand.php b/src/Command/FixerWorkerCommand.php index fbb811917d2..7d55af74bb7 100644 --- a/src/Command/FixerWorkerCommand.php +++ b/src/Command/FixerWorkerCommand.php @@ -281,9 +281,9 @@ function (array $errors, array $locallyIgnoredErrors, array $analysedFiles) use new InternalError( 'Internal error occurred', 'running analyser in PHPStan Pro worker', - [], - null, - false, + trace: [], + traceAsString: null, + shouldReportBug: false, ), ], ]]); @@ -349,7 +349,7 @@ private function transformErrorIntoInternalError(Error $error): InternalError sprintf('analysing file %s', $error->getTraitFilePath() ?? $error->getFilePath()), $metadata[InternalError::STACK_TRACE_METADATA_KEY] ?? [], $metadata[InternalError::STACK_TRACE_AS_STRING_METADATA_KEY] ?? null, - true, + shouldReportBug: true, ); } @@ -390,7 +390,21 @@ private function runAnalyser(LoopInterface $loop, Container $container, array $f $parallelAnalyser = $container->getByType(ParallelAnalyser::class); $filesCount = count($files); if ($filesCount === 0) { - return resolve(new AnalyserResult([], [], [], [], [], [], [], [], [], [], [], false, memory_get_peak_usage(true))); + return resolve(new AnalyserResult( + unorderedErrors: [], + filteredPhpErrors: [], + allPhpErrors: [], + locallyIgnoredErrors: [], + linesToIgnore: [], + unmatchedLineIgnores: [], + internalErrors: [], + collectedData: [], + dependencies: [], + usedTraitDependencies: [], + exportedNodes: [], + reachedInternalErrorsCountLimit: false, + peakMemoryUsageBytes: memory_get_peak_usage(true), + )); } /** @var Scheduler $scheduler */ diff --git a/src/Command/IgnoredRegexValidator.php b/src/Command/IgnoredRegexValidator.php index 4340e0bd991..fc096bdb782 100644 --- a/src/Command/IgnoredRegexValidator.php +++ b/src/Command/IgnoredRegexValidator.php @@ -33,20 +33,20 @@ public function validate(string $regex): IgnoredRegexValidatorResult /** @var TreeNode $ast */ $ast = $this->parser->parse($regex); } catch (Exception) { - return new IgnoredRegexValidatorResult([], false, false); + return new IgnoredRegexValidatorResult(ignoredTypes: [], anchorsInTheMiddle: false, allErrorsIgnored: false); } if (Strings::match($regex, '~(?getIgnoredTypes($ast), - $this->hasAnchorsInTheMiddle($ast), - false, + ignoredTypes: $this->getIgnoredTypes($ast), + anchorsInTheMiddle: $this->hasAnchorsInTheMiddle($ast), + allErrorsIgnored: false, ); } diff --git a/src/Command/WorkerCommand.php b/src/Command/WorkerCommand.php index 902c9055a23..2a221f6e846 100644 --- a/src/Command/WorkerCommand.php +++ b/src/Command/WorkerCommand.php @@ -187,7 +187,7 @@ private function runWorker( 'communicating with main process in parallel worker', InternalError::prepareTrace($error), $error->getTraceAsString(), - true, + shouldReportBug: true, ), ], 'filteredPhpErrors' => [], @@ -262,7 +262,7 @@ private function runWorker( sprintf('analysing file %s', $file), InternalError::prepareTrace($t), $t->getTraceAsString(), - true, + shouldReportBug: true, ); } } diff --git a/src/Dependency/ExportedNode/ExportedTraitUseAdaptation.php b/src/Dependency/ExportedNode/ExportedTraitUseAdaptation.php index 3ddc6a18ddb..f08de3eeacc 100644 --- a/src/Dependency/ExportedNode/ExportedTraitUseAdaptation.php +++ b/src/Dependency/ExportedNode/ExportedTraitUseAdaptation.php @@ -30,7 +30,7 @@ public static function createAlias( ?string $newName, ): self { - return new self($traitName, $method, $newModifier, $newName, null); + return new self($traitName, $method, $newModifier, $newName, insteadOfs: null); } /** @@ -42,7 +42,7 @@ public static function createPrecedence( array $insteadOfs, ): self { - return new self($traitName, $method, null, null, $insteadOfs); + return new self($traitName, $method, newModifier: null, newName: null, insteadOfs: $insteadOfs); } public function equals(ExportedNode $node): bool diff --git a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php index 2732bbdb05d..c01cc4c94e1 100644 --- a/src/DependencyInjection/ValidateIgnoredErrorsExtension.php +++ b/src/DependencyInjection/ValidateIgnoredErrorsExtension.php @@ -86,7 +86,7 @@ public function loadConfiguration(): void try { $composerPhpVersionFactory = new ComposerPhpVersionFactory([]); - $constantResolver = new ConstantResolver($reflectionProviderProvider, [], null, $composerPhpVersionFactory, null); + $constantResolver = new ConstantResolver($reflectionProviderProvider, [], phpVersion: null, composerPhpVersionFactory: $composerPhpVersionFactory, container: null); $phpDocParserConfig = new ParserConfig([]); $ignoredRegexValidator = new IgnoredRegexValidator( diff --git a/src/Parallel/ParallelAnalyser.php b/src/Parallel/ParallelAnalyser.php index 8503d826e03..7792a0cb6ba 100644 --- a/src/Parallel/ParallelAnalyser.php +++ b/src/Parallel/ParallelAnalyser.php @@ -102,27 +102,27 @@ public function analyse( $internalErrors[] = new InternalError( 'Some parallel worker jobs have not finished.', 'running parallel worker', - [], - null, - true, + trace: [], + traceAsString: null, + shouldReportBug: true, ); $internalErrorsCount++; } $deferred->resolve(new AnalyserResult( - $errors, - $filteredPhpErrors, - $allPhpErrors, - $locallyIgnoredErrors, - $linesToIgnore, - $unmatchedLineIgnores, - $internalErrors, - $collectedData, - $internalErrorsCount === 0 ? $dependencies : null, - $internalErrorsCount === 0 ? $usedTraitDependencies : null, - $exportedNodes, - $reachedInternalErrorsCountLimit, - array_sum($peakMemoryUsages), // not 100% correct as the peak usages of workers might not have met + unorderedErrors: $errors, + filteredPhpErrors: $filteredPhpErrors, + allPhpErrors: $allPhpErrors, + locallyIgnoredErrors: $locallyIgnoredErrors, + linesToIgnore: $linesToIgnore, + unmatchedLineIgnores: $unmatchedLineIgnores, + internalErrors: $internalErrors, + collectedData: $collectedData, + dependencies: $internalErrorsCount === 0 ? $dependencies : null, + usedTraitDependencies: $internalErrorsCount === 0 ? $usedTraitDependencies : null, + exportedNodes: $exportedNodes, + reachedInternalErrorsCountLimit: $reachedInternalErrorsCountLimit, + peakMemoryUsageBytes: array_sum($peakMemoryUsages), // not 100% correct as the peak usages of workers might not have met )); }); $server->on('connection', function (ConnectionInterface $connection) use (&$jobs): void { @@ -160,7 +160,7 @@ public function analyse( 'communicating with parallel worker', InternalError::prepareTrace($error), $error->getTraceAsString(), - !$error instanceof ProcessTimedOutException, + shouldReportBug: !$error instanceof ProcessTimedOutException, ); $internalErrorsCount++; $reachedInternalErrorsCountLimit = true; @@ -332,13 +332,13 @@ public function analyse( $memoryLimitMessage, ini_get('memory_limit'), 'Increase your memory limit in php.ini or run PHPStan with --memory-limit CLI option.', - ), 'running parallel worker', [], null, false); + ), 'running parallel worker', trace: [], traceAsString: null, shouldReportBug: false); $internalErrorsCount++; $this->processPool->tryQuitProcess($processIdentifier); return; } - $internalErrors[] = new InternalError(sprintf('Child process error (exit code %d): %s', $exitCode, $output), 'running parallel worker', [], null, true); + $internalErrors[] = new InternalError(sprintf('Child process error (exit code %d): %s', $exitCode, $output), 'running parallel worker', trace: [], traceAsString: null, shouldReportBug: true); $internalErrorsCount++; $this->processPool->tryQuitProcess($processIdentifier); }); diff --git a/src/PhpDoc/PhpDocNodeResolver.php b/src/PhpDoc/PhpDocNodeResolver.php index 37e7c3c9fe0..1e88dce58aa 100644 --- a/src/PhpDoc/PhpDocNodeResolver.php +++ b/src/PhpDoc/PhpDocNodeResolver.php @@ -578,20 +578,20 @@ private function resolveAssertTagsFor(PhpDocNode $phpDocNode, NameScope $nameSco foreach ($phpDocNode->getAssertTagValues($tagName) as $assertTagValue) { $type = $this->typeNodeResolver->resolve($assertTagValue->type, $nameScope); - $parameter = new AssertTagParameter($assertTagValue->parameter, null, null); - $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, true); + $parameter = new AssertTagParameter($assertTagValue->parameter, property: null, method: null); + $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, isExplicit: true); } foreach ($phpDocNode->getAssertPropertyTagValues($tagName) as $assertTagValue) { $type = $this->typeNodeResolver->resolve($assertTagValue->type, $nameScope); - $parameter = new AssertTagParameter($assertTagValue->parameter, $assertTagValue->property, null); - $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, true); + $parameter = new AssertTagParameter($assertTagValue->parameter, property: $assertTagValue->property, method: null); + $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, isExplicit: true); } foreach ($phpDocNode->getAssertMethodTagValues($tagName) as $assertTagValue) { $type = $this->typeNodeResolver->resolve($assertTagValue->type, $nameScope); - $parameter = new AssertTagParameter($assertTagValue->parameter, null, $assertTagValue->method); - $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, true); + $parameter = new AssertTagParameter($assertTagValue->parameter, property: null, method: $assertTagValue->method); + $resolved[] = new AssertTag($if, $type, $parameter, $assertTagValue->isNegated, $assertTagValue->isEquality, isExplicit: true); } return $resolved; diff --git a/src/PhpDoc/StubValidator.php b/src/PhpDoc/StubValidator.php index 2b57559ca30..52c207e7c76 100644 --- a/src/PhpDoc/StubValidator.php +++ b/src/PhpDoc/StubValidator.php @@ -202,8 +202,8 @@ private function getRuleRegistry(Container $container): RuleRegistry $methodTagTemplateTypeCheck = $container->getByType(MethodTagTemplateTypeCheck::class); $mixinCheck = $container->getByType(MixinCheck::class); $discoveringSymbolsTip = $container->getParameter('tips')['discoveringSymbols']; - $methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true, $discoveringSymbolsTip); - $propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, true, true, $discoveringSymbolsTip); + $methodTagCheck = new MethodTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, checkClassCaseSensitivity: true, checkMissingTypehints: true, discoveringSymbolsTip: $discoveringSymbolsTip); + $propertyTagCheck = new PropertyTagCheck($reflectionProvider, $classNameCheck, $genericObjectTypeCheck, $missingTypehintCheck, $unresolvableTypeHelper, checkClassCaseSensitivity: true, checkMissingTypehints: true, discoveringSymbolsTip: $discoveringSymbolsTip); $reflector = $container->getService('stubReflector'); $relativePathHelper = $container->getService('simpleRelativePathHelper'); $assertRuleHelper = $container->getByType(AssertRuleHelper::class); @@ -218,10 +218,10 @@ private function getRuleRegistry(Container $container): RuleRegistry new ExistingClassInTraitUseRule($classNameCheck, $reflectionProvider, $discoveringSymbolsTip), new ExistingClassesInTypehintsRule($functionDefinitionCheck), new \PHPStan\Rules\Functions\ExistingClassesInTypehintsRule($functionDefinitionCheck), - new ExistingClassesInPropertiesRule($reflectionProvider, $classNameCheck, $unresolvableTypeHelper, $phpVersion, true, false, $discoveringSymbolsTip), + new ExistingClassesInPropertiesRule($reflectionProvider, $classNameCheck, $unresolvableTypeHelper, $phpVersion, checkClassCaseSensitivity: true, checkThisOnly: false, discoveringSymbolsTip: $discoveringSymbolsTip), new OverridingMethodRule( $phpVersion, - new MethodSignatureRule($parentMethodHelper, true, true), + new MethodSignatureRule($parentMethodHelper, reportMaybes: true, reportStatic: true), true, new MethodParameterComparisonHelper($phpVersion), new MethodVisibilityComparisonHelper(), diff --git a/src/PhpDoc/TypeNodeResolver.php b/src/PhpDoc/TypeNodeResolver.php index 7ad5d80e298..8af74bf9264 100644 --- a/src/PhpDoc/TypeNodeResolver.php +++ b/src/PhpDoc/TypeNodeResolver.php @@ -1007,7 +1007,7 @@ function (CallableTypeParameterNode $parameterNode) use ($nameScope, &$isVariadi $this->resolve($parameterNode->type, $nameScope), $parameterNode->isReference ? PassedByReference::createCreatesNewVariable() : PassedByReference::createNo(), $parameterNode->isVariadic, - null, + defaultValue: null, ); }, $typeNode->parameters, diff --git a/src/Reflection/Callables/SimpleThrowPoint.php b/src/Reflection/Callables/SimpleThrowPoint.php index 3e7c510f811..5ccd3ed18d1 100644 --- a/src/Reflection/Callables/SimpleThrowPoint.php +++ b/src/Reflection/Callables/SimpleThrowPoint.php @@ -35,7 +35,7 @@ public static function createExplicit(Type $type, bool $canContainAnyThrowable): public static function createImplicit(): self { - return new self(new ObjectType(Throwable::class), false, true); + return new self(new ObjectType(Throwable::class), explicit: false, canContainAnyThrowable: true); } public function getType(): Type diff --git a/src/Reflection/InitializerExprContext.php b/src/Reflection/InitializerExprContext.php index e6fb8ab6e5b..a148db9f51b 100644 --- a/src/Reflection/InitializerExprContext.php +++ b/src/Reflection/InitializerExprContext.php @@ -209,7 +209,15 @@ public static function fromGlobalConstant(ReflectionConstant $constant): self public static function createEmpty(): self { - return new self(null, null, null, null, null, null, null); + return new self( + file: null, + namespace: null, + className: null, + traitName: null, + function: null, + method: null, + property: null, + ); } public function getFile(): ?string diff --git a/src/Reflection/ParametersAcceptorSelector.php b/src/Reflection/ParametersAcceptorSelector.php index 596dcc4be04..20317a14053 100644 --- a/src/Reflection/ParametersAcceptorSelector.php +++ b/src/Reflection/ParametersAcceptorSelector.php @@ -95,12 +95,12 @@ public static function selectFromArgs( foreach ($constantArrays as $constantArray) { $valueTypes = $constantArray->getValueTypes(); foreach ($valueTypes as $valueType) { - $callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($valueType), false, PassedByReference::createNo(), false, null); + $callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($valueType), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null); } } } } else { - $callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($argType), false, PassedByReference::createNo(), false, null); + $callbackParameters[] = new DummyParameter('item', $scope->getIterableValueType($argType), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null); } } @@ -233,12 +233,12 @@ public static function selectFromArgs( if ($mode instanceof ConstantIntegerType) { if ($mode->getValue() === ARRAY_FILTER_USE_KEY) { $arrayFilterParameters = [ - new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null), + new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ]; } elseif ($mode->getValue() === ARRAY_FILTER_USE_BOTH) { $arrayFilterParameters = [ - new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null), - new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null), + new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), + new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ]; } } @@ -253,7 +253,7 @@ public static function selectFromArgs( new UnionType([ new CallableType( $arrayFilterParameters ?? [ - new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null), + new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ], new BooleanType(), false, @@ -285,12 +285,12 @@ public static function selectFromArgs( && isset($parameters[0]) && isset($parameters[1]) ) { $parameters = [ - new NativeParameterReflection($parameters[0]->getName(), false, new StringType(), PassedByReference::createNo(), false, null), - new NativeParameterReflection($parameters[1]->getName(), false, new ArrayType(new MixedType(), new MixedType()), PassedByReference::createNo(), false, null), + new NativeParameterReflection($parameters[0]->getName(), optional: false, type: new StringType(), passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), + new NativeParameterReflection($parameters[1]->getName(), optional: false, type: new ArrayType(new MixedType(), new MixedType()), passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ]; } elseif (isset($parameters[0])) { $parameters = [ - new NativeParameterReflection($parameters[0]->getName(), false, new ArrayType(new MixedType(), new MixedType()), PassedByReference::createNo(), false, null), + new NativeParameterReflection($parameters[0]->getName(), optional: false, type: new ArrayType(new MixedType(), new MixedType()), passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ]; } @@ -308,11 +308,11 @@ public static function selectFromArgs( if ((bool) $args[0]->getAttribute(ArrayWalkArgVisitor::ATTRIBUTE_NAME)) { $arrayWalkParameters = [ - new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), false, PassedByReference::createReadsArgument(), false, null), - new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), false, PassedByReference::createNo(), false, null), + new DummyParameter('item', $scope->getIterableValueType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createReadsArgument(), variadic: false, defaultValue: null), + new DummyParameter('key', $scope->getIterableKeyType($scope->getType($args[0]->value)), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ]; if (isset($args[2])) { - $arrayWalkParameters[] = new DummyParameter('arg', $scope->getType($args[2]->value), false, PassedByReference::createNo(), false, null); + $arrayWalkParameters[] = new DummyParameter('arg', $scope->getType($args[2]->value), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null); } $acceptor = $parametersAcceptors[0]; @@ -349,8 +349,8 @@ public static function selectFromArgs( $parameters[1]->isOptional(), new CallableType( [ - new DummyParameter('value', $scope->getIterableValueType($argType), false, PassedByReference::createNo(), false, null), - new DummyParameter('key', $scope->getIterableKeyType($argType), false, PassedByReference::createNo(), false, null), + new DummyParameter('value', $scope->getIterableValueType($argType), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), + new DummyParameter('key', $scope->getIterableKeyType($argType), optional: false, passedByReference: PassedByReference::createNo(), variadic: false, defaultValue: null), ], new BooleanType(), false, diff --git a/src/Reflection/Php/ClosureCallMethodReflection.php b/src/Reflection/Php/ClosureCallMethodReflection.php index 7af6299b96c..b15ec9401b9 100644 --- a/src/Reflection/Php/ClosureCallMethodReflection.php +++ b/src/Reflection/Php/ClosureCallMethodReflection.php @@ -72,11 +72,11 @@ public function getVariants(): array $parameters = $this->closureType->getParameters(); $newThis = new NativeParameterReflection( 'newThis', - false, - new ObjectWithoutClassType(), - PassedByReference::createNo(), - false, - null, + optional: false, + type: new ObjectWithoutClassType(), + passedByReference: PassedByReference::createNo(), + variadic: false, + defaultValue: null, ); array_unshift($parameters, $newThis); diff --git a/src/Testing/PHPStanTestCase.php b/src/Testing/PHPStanTestCase.php index 89ee716a194..1a36ad4d421 100644 --- a/src/Testing/PHPStanTestCase.php +++ b/src/Testing/PHPStanTestCase.php @@ -142,7 +142,7 @@ public static function createScopeFactory(ReflectionProvider $reflectionProvider $reflectionProviderProvider = new DirectReflectionProviderProvider($reflectionProvider); $composerPhpVersionFactory = $container->getByType(ComposerPhpVersionFactory::class); - $constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames, null, $composerPhpVersionFactory, $container); + $constantResolver = new ConstantResolver($reflectionProviderProvider, $dynamicConstantNames, phpVersion: null, composerPhpVersionFactory: $composerPhpVersionFactory, container: $container); $initializerExprTypeResolver = new InitializerExprTypeResolver( $constantResolver, diff --git a/src/Type/CallableType.php b/src/Type/CallableType.php index cf9998fbe22..6e2c98b88cb 100644 --- a/src/Type/CallableType.php +++ b/src/Type/CallableType.php @@ -325,10 +325,10 @@ function (): string { array_map(static fn (ParameterReflection $p): ParameterReflection => new DummyParameter( '', $p->getType(), - $p->isOptional() && !$p->isVariadic(), - PassedByReference::createNo(), - $p->isVariadic(), - $p->getDefaultValue(), + optional: $p->isOptional() && !$p->isVariadic(), + passedByReference: PassedByReference::createNo(), + variadic: $p->isVariadic(), + defaultValue: $p->getDefaultValue(), ), $this->parameters), $this->returnType, $this->variadic, diff --git a/src/Type/ClosureType.php b/src/Type/ClosureType.php index b9267e05c52..69bc2752f09 100644 --- a/src/Type/ClosureType.php +++ b/src/Type/ClosureType.php @@ -138,7 +138,17 @@ public function getTemplateTags(): array public static function createPure(): self { - return new self(null, null, true, null, null, null, [], [], []); + return new self( + parameters: null, + returnType: null, + variadic: true, + templateTypeMap: null, + resolvedTemplateTypeMap: null, + callSiteVarianceMap: null, + templateTags: [], + throwPoints: [], + impurePoints: [], + ); } public function isPure(): TrinaryLogic @@ -263,10 +273,10 @@ function (): string { array_map(static fn (ParameterReflection $p): ParameterReflection => new DummyParameter( '', $p->getType(), - $p->isOptional() && !$p->isVariadic(), - PassedByReference::createNo(), - $p->isVariadic(), - $p->getDefaultValue(), + optional: $p->isOptional() && !$p->isVariadic(), + passedByReference: PassedByReference::createNo(), + variadic: $p->isVariadic(), + defaultValue: $p->getDefaultValue(), ), $this->parameters), $this->returnType, $this->variadic, diff --git a/src/Type/TypeUtils.php b/src/Type/TypeUtils.php index 9c3ced7a1e0..7ef64cac666 100644 --- a/src/Type/TypeUtils.php +++ b/src/Type/TypeUtils.php @@ -215,7 +215,7 @@ public static function getHasPropertyTypes(Type $type): array */ public static function getAccessoryTypes(Type $type): array { - return self::map(AccessoryType::class, $type, true, false); + return self::map(AccessoryType::class, $type, inspectIntersections: true, stopOnUnmatched: false); } public static function containsTemplateType(Type $type): bool