Skip to content

Commit 1d4477f

Browse files
committed
Auto-apply fixes for NamedArgumentsRule
1 parent 6680175 commit 1d4477f

File tree

79 files changed

+235
-293
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

79 files changed

+235
-293
lines changed

src/Analyser/Analyser.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -103,7 +103,7 @@ public function analyse(
103103
throw $t;
104104
}
105105
$internalErrorsCount++;
106-
$errors[] = (new Error($t->getMessage(), $file, null, $t))
106+
$errors[] = (new Error($t->getMessage(), $file, canBeIgnored: $t))
107107
->withIdentifier('phpstan.internal')
108108
->withMetadata([
109109
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($t),

src/Analyser/AnalyserResultFinalizer.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,15 +50,15 @@ public function finalize(AnalyserResult $analyserResult, bool $onlyFiles, bool $
5050
try {
5151
$ruleErrors = $rule->processNode($node, $scope);
5252
} catch (AnalysedCodeException $e) {
53-
$tempCollectorErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, null, null, $e->getTip()))
53+
$tempCollectorErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, tip: $e->getTip()))
5454
->withIdentifier('phpstan.internal')
5555
->withMetadata([
5656
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
5757
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
5858
]);
5959
continue;
6060
} catch (IdentifierNotFound $e) {
61-
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
61+
$tempCollectorErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, tip: 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
6262
->withIdentifier('phpstan.reflection')
6363
->withMetadata([
6464
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),

src/Analyser/FileAnalyser.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -122,15 +122,15 @@ public function analyseFile(
122122
}
123123

124124
$uniquedAnalysedCodeExceptionMessages[$e->getMessage()] = true;
125-
$fileErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, null, null, $e->getTip()))
125+
$fileErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, tip: $e->getTip()))
126126
->withIdentifier('phpstan.internal')
127127
->withMetadata([
128128
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
129129
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
130130
]);
131131
continue;
132132
} catch (IdentifierNotFound $e) {
133-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
133+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, tip: 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
134134
->withIdentifier('phpstan.reflection')
135135
->withMetadata([
136136
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
@@ -171,15 +171,15 @@ public function analyseFile(
171171
}
172172

173173
$uniquedAnalysedCodeExceptionMessages[$e->getMessage()] = true;
174-
$fileErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, null, null, $e->getTip()))
174+
$fileErrors[] = (new Error($e->getMessage(), $file, $node->getStartLine(), $e, tip: $e->getTip()))
175175
->withIdentifier('phpstan.internal')
176176
->withMetadata([
177177
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
178178
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
179179
]);
180180
continue;
181181
} catch (IdentifierNotFound $e) {
182-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
182+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, $node->getStartLine(), $e, tip: 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
183183
->withIdentifier('phpstan.reflection')
184184
->withMetadata([
185185
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
@@ -257,31 +257,31 @@ public function analyseFile(
257257
$fileErrors[] = (new Error($error->getMessage(), $e->getParsedFile() ?? $file, $error->getLine() !== -1 ? $error->getStartLine() : null, $e))->withIdentifier('phpstan.parse');
258258
}
259259
} catch (AnalysedCodeException $e) {
260-
$fileErrors[] = (new Error($e->getMessage(), $file, null, $e, null, null, $e->getTip()))
260+
$fileErrors[] = (new Error($e->getMessage(), $file, canBeIgnored: $e, tip: $e->getTip()))
261261
->withIdentifier('phpstan.internal')
262262
->withMetadata([
263263
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
264264
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
265265
]);
266266
} catch (IdentifierNotFound $e) {
267-
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, null, $e, null, null, 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
267+
$fileErrors[] = (new Error(sprintf('Reflection error: %s not found.', $e->getIdentifier()->getName()), $file, canBeIgnored: $e, tip: 'Learn more at https://phpstan.org/user-guide/discovering-symbols'))
268268
->withIdentifier('phpstan.reflection')
269269
->withMetadata([
270270
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
271271
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
272272
]);
273273
} catch (UnableToCompileNode | CircularReference $e) {
274-
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, null, $e))
274+
$fileErrors[] = (new Error(sprintf('Reflection error: %s', $e->getMessage()), $file, canBeIgnored: $e))
275275
->withIdentifier('phpstan.reflection')
276276
->withMetadata([
277277
InternalError::STACK_TRACE_METADATA_KEY => InternalError::prepareTrace($e),
278278
InternalError::STACK_TRACE_AS_STRING_METADATA_KEY => $e->getTraceAsString(),
279279
]);
280280
}
281281
} elseif (is_dir($file)) {
282-
$fileErrors[] = (new Error(sprintf('File %s is a directory.', $file), $file, null, false))->withIdentifier('phpstan.path');
282+
$fileErrors[] = (new Error(sprintf('File %s is a directory.', $file), $file, canBeIgnored: false))->withIdentifier('phpstan.path');
283283
} else {
284-
$fileErrors[] = (new Error(sprintf('File %s does not exist.', $file), $file, null, false))->withIdentifier('phpstan.path');
284+
$fileErrors[] = (new Error(sprintf('File %s does not exist.', $file), $file, canBeIgnored: false))->withIdentifier('phpstan.path');
285285
}
286286

287287
$this->restoreCollectErrorsHandler();

src/Analyser/Ignore/IgnoredErrorHelperResult.php

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -224,8 +224,7 @@ public function process(
224224
IgnoredError::stringifyPattern($unmatchedIgnoredError),
225225
),
226226
$unmatchedIgnoredError['realPath'],
227-
null,
228-
false,
227+
canBeIgnored: false,
229228
))->withIdentifier('ignore.unmatched');
230229
} elseif (!$onlyFiles) {
231230
$stringErrors[] = sprintf(

src/Analyser/MutatingScope.php

Lines changed: 20 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1415,12 +1415,11 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
14151415
TemplateTypeMap::createEmpty(),
14161416
TemplateTypeMap::createEmpty(),
14171417
TemplateTypeVarianceMap::createEmpty(),
1418-
[],
1419-
$cachedClosureData['throwPoints'],
1420-
$cachedClosureData['impurePoints'],
1421-
$cachedClosureData['invalidateExpressions'],
1422-
$cachedClosureData['usedVariables'],
1423-
TrinaryLogic::createYes(),
1418+
throwPoints: $cachedClosureData['throwPoints'],
1419+
impurePoints: $cachedClosureData['impurePoints'],
1420+
invalidateExpressions: $cachedClosureData['invalidateExpressions'],
1421+
usedVariables: $cachedClosureData['usedVariables'],
1422+
acceptsNamedArguments: TrinaryLogic::createYes(),
14241423
);
14251424
}
14261425
if (self::$resolveClosureTypeDepth >= 2) {
@@ -1630,12 +1629,11 @@ static function (Node $node, Scope $scope) use ($arrowScope, &$arrowFunctionImpu
16301629
TemplateTypeMap::createEmpty(),
16311630
TemplateTypeMap::createEmpty(),
16321631
TemplateTypeVarianceMap::createEmpty(),
1633-
[],
1634-
$throwPointsForClosureType,
1635-
$impurePointsForClosureType,
1636-
$invalidateExpressions,
1637-
$usedVariables,
1638-
TrinaryLogic::createYes(),
1632+
throwPoints: $throwPointsForClosureType,
1633+
impurePoints: $impurePointsForClosureType,
1634+
invalidateExpressions: $invalidateExpressions,
1635+
usedVariables: $usedVariables,
1636+
acceptsNamedArguments: TrinaryLogic::createYes(),
16391637
);
16401638
} elseif ($node instanceof New_) {
16411639
if ($node->class instanceof Name) {
@@ -3140,7 +3138,7 @@ public function enterPropertyHook(
31403138
if ($hook->params === []) {
31413139
$hook = clone $hook;
31423140
$hook->params = [
3143-
new Node\Param(new Variable('value'), null, $nativePropertyTypeNode),
3141+
new Node\Param(new Variable('value'), type: $nativePropertyTypeNode),
31443142
];
31453143
}
31463144

@@ -5805,7 +5803,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58055803
return $methodResult;
58065804
}
58075805

5808-
$objectType = $isStatic ? new StaticType($classReflection) : new ObjectType($resolvedClassName, null, $classReflection);
5806+
$objectType = $isStatic ? new StaticType($classReflection) : new ObjectType($resolvedClassName, classReflection: $classReflection);
58095807
if (!$classReflection->isGeneric()) {
58105808
return $objectType;
58115809
}
@@ -5831,7 +5829,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58315829

58325830
if (count($classTemplateTypes) === count($originalClassTemplateTypes)) {
58335831
$propertyType = TypeCombinator::removeNull($this->getType($assignedToProperty));
5834-
$nonFinalObjectType = $isStatic ? new StaticType($nonFinalClassReflection) : new ObjectType($resolvedClassName, null, $nonFinalClassReflection);
5832+
$nonFinalObjectType = $isStatic ? new StaticType($nonFinalClassReflection) : new ObjectType($resolvedClassName, classReflection: $nonFinalClassReflection);
58355833
if ($nonFinalObjectType->isSuperTypeOf($propertyType)->yes()) {
58365834
return $propertyType;
58375835
}
@@ -5852,8 +5850,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58525850
return new GenericObjectType(
58535851
$resolvedClassName,
58545852
$types,
5855-
null,
5856-
$classReflection->withTypes($types)->asFinal(),
5853+
classReflection: $classReflection->withTypes($types)->asFinal(),
58575854
);
58585855
}
58595856

@@ -5872,8 +5869,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58725869
return new GenericObjectType(
58735870
$resolvedClassName,
58745871
$types,
5875-
null,
5876-
$classReflection->withTypes($types)->asFinal(),
5872+
classReflection: $classReflection->withTypes($types)->asFinal(),
58775873
);
58785874
}
58795875
$newType = new GenericObjectType($resolvedClassName, $classReflection->typeMapToList($classReflection->getTemplateTypeMap()));
@@ -5892,8 +5888,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
58925888
return new GenericObjectType(
58935889
$resolvedClassName,
58945890
$types,
5895-
null,
5896-
$classReflection->withTypes($types)->asFinal(),
5891+
classReflection: $classReflection->withTypes($types)->asFinal(),
58975892
);
58985893
}
58995894
$ancestorClassReflections = $ancestorType->getObjectClassReflections();
@@ -5911,8 +5906,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
59115906
return new GenericObjectType(
59125907
$resolvedClassName,
59135908
$types,
5914-
null,
5915-
$classReflection->withTypes($types)->asFinal(),
5909+
classReflection: $classReflection->withTypes($types)->asFinal(),
59165910
);
59175911
}
59185912

@@ -5933,8 +5927,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
59335927
return new GenericObjectType(
59345928
$resolvedClassName,
59355929
$types,
5936-
null,
5937-
$classReflection->withTypes($types)->asFinal(),
5930+
classReflection: $classReflection->withTypes($types)->asFinal(),
59385931
);
59395932
}
59405933
$newParentTypeClassReflection = $newParentTypeClassReflections[0];
@@ -5981,8 +5974,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
59815974
return new GenericObjectType(
59825975
$resolvedClassName,
59835976
$types,
5984-
null,
5985-
$classReflection->withTypes($types)->asFinal(),
5977+
classReflection: $classReflection->withTypes($types)->asFinal(),
59865978
);
59875979
}
59885980

@@ -5998,8 +5990,7 @@ private function exactInstantiation(New_ $node, string $className): ?Type
59985990
$newGenericType = new GenericObjectType(
59995991
$resolvedClassName,
60005992
$types,
6001-
null,
6002-
$classReflection->withTypes($types)->asFinal(),
5993+
classReflection: $classReflection->withTypes($types)->asFinal(),
60035994
);
60045995
if ($isStatic) {
60055996
$newGenericType = new GenericStaticType(

src/Analyser/TypeSpecifier.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ private function createRangeTypes(?Expr $rootExpr, Expr $expr, Type $type, TypeS
18981898
}
18991899
}
19001900

1901-
return (new SpecifiedTypes([], $sureNotTypes))->setRootExpr($rootExpr);
1901+
return (new SpecifiedTypes(sureNotTypes: $sureNotTypes))->setRootExpr($rootExpr);
19021902
}
19031903

19041904
/**
@@ -2263,7 +2263,7 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
22632263
if ($rightType instanceof ConstantStringType && $this->reflectionProvider->hasClass($rightType->getValue())) {
22642264
return $this->create(
22652265
$unwrappedLeftExpr->getArgs()[0]->value,
2266-
new ObjectType($rightType->getValue(), null, $this->reflectionProvider->getClass($rightType->getValue())->asFinal()),
2266+
new ObjectType($rightType->getValue(), classReflection: $this->reflectionProvider->getClass($rightType->getValue())->asFinal()),
22672267
$context,
22682268
$scope,
22692269
)->unionWith($this->create($leftExpr, $rightType, $context, $scope))->setRootExpr($expr);
@@ -2370,7 +2370,7 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
23702370
if ($this->reflectionProvider->hasClass($rightType->getValue())) {
23712371
return $this->create(
23722372
$unwrappedLeftExpr->class,
2373-
new ObjectType($rightType->getValue(), null, $this->reflectionProvider->getClass($rightType->getValue())->asFinal()),
2373+
new ObjectType($rightType->getValue(), classReflection: $this->reflectionProvider->getClass($rightType->getValue())->asFinal()),
23742374
$context,
23752375
$scope,
23762376
)->unionWith($this->create($leftExpr, $rightType, $context, $scope))->setRootExpr($expr);
@@ -2401,7 +2401,7 @@ public function resolveIdentical(Expr\BinaryOp\Identical $expr, Scope $scope, Ty
24012401
if ($this->reflectionProvider->hasClass($leftType->getValue())) {
24022402
return $this->create(
24032403
$unwrappedRightExpr->class,
2404-
new ObjectType($leftType->getValue(), null, $this->reflectionProvider->getClass($leftType->getValue())->asFinal()),
2404+
new ObjectType($leftType->getValue(), classReflection: $this->reflectionProvider->getClass($leftType->getValue())->asFinal()),
24052405
$context,
24062406
$scope,
24072407
)->unionWith($this->create($rightExpr, $leftType, $context, $scope)->setRootExpr($expr));

src/Command/AnalyseCommand.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -100,20 +100,20 @@ protected function configure(): void
100100
new InputArgument('paths', InputArgument::OPTIONAL | InputArgument::IS_ARRAY, 'Paths with source code to run analysis on'),
101101
new InputOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Path to project configuration file'),
102102
new InputOption(self::OPTION_LEVEL, 'l', InputOption::VALUE_REQUIRED, 'Level of rule options - the higher the stricter'),
103-
new InputOption(ErrorsConsoleStyle::OPTION_NO_PROGRESS, null, InputOption::VALUE_NONE, 'Do not show progress bar, only results'),
104-
new InputOption('debug', null, InputOption::VALUE_NONE, 'Show debug information - which file is analysed, do not catch internal errors'),
103+
new InputOption(ErrorsConsoleStyle::OPTION_NO_PROGRESS, mode: InputOption::VALUE_NONE, description: 'Do not show progress bar, only results'),
104+
new InputOption('debug', mode: InputOption::VALUE_NONE, description: 'Show debug information - which file is analysed, do not catch internal errors'),
105105
new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'),
106-
new InputOption('error-format', null, InputOption::VALUE_REQUIRED, 'Format in which to print the result of the analysis', null),
106+
new InputOption('error-format', mode: InputOption::VALUE_REQUIRED, description: 'Format in which to print the result of the analysis'),
107107
new InputOption('generate-baseline', 'b', InputOption::VALUE_OPTIONAL, 'Path to a file where the baseline should be saved', false),
108-
new InputOption('allow-empty-baseline', null, InputOption::VALUE_NONE, 'Do not error out when the generated baseline is empty'),
109-
new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for analysis'),
110-
new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with Xdebug for debugging purposes'),
111-
new InputOption('tmp-file', null, InputOption::VALUE_REQUIRED, '(Editor mode) Edited file used in place of --instead-of file'),
112-
new InputOption('instead-of', null, InputOption::VALUE_REQUIRED, '(Editor mode) File being replaced by --tmp-file'),
113-
new InputOption('fix', null, InputOption::VALUE_NONE, 'Fix auto-fixable errors (experimental)'),
114-
new InputOption('watch', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'),
115-
new InputOption('pro', null, InputOption::VALUE_NONE, 'Launch PHPStan Pro'),
116-
new InputOption('fail-without-result-cache', null, InputOption::VALUE_NONE, 'Return non-zero exit code when result cache is not used'),
108+
new InputOption('allow-empty-baseline', mode: InputOption::VALUE_NONE, description: 'Do not error out when the generated baseline is empty'),
109+
new InputOption('memory-limit', mode: InputOption::VALUE_REQUIRED, description: 'Memory limit for analysis'),
110+
new InputOption('xdebug', mode: InputOption::VALUE_NONE, description: 'Allow running with Xdebug for debugging purposes'),
111+
new InputOption('tmp-file', mode: InputOption::VALUE_REQUIRED, description: '(Editor mode) Edited file used in place of --instead-of file'),
112+
new InputOption('instead-of', mode: InputOption::VALUE_REQUIRED, description: '(Editor mode) File being replaced by --tmp-file'),
113+
new InputOption('fix', mode: InputOption::VALUE_NONE, description: 'Fix auto-fixable errors (experimental)'),
114+
new InputOption('watch', mode: InputOption::VALUE_NONE, description: 'Launch PHPStan Pro'),
115+
new InputOption('pro', mode: InputOption::VALUE_NONE, description: 'Launch PHPStan Pro'),
116+
new InputOption('fail-without-result-cache', mode: InputOption::VALUE_NONE, description: 'Return non-zero exit code when result cache is not used'),
117117
]);
118118
}
119119

src/Command/ClearResultCacheCommand.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@ protected function configure(): void
3333
->setDefinition([
3434
new InputOption('configuration', 'c', InputOption::VALUE_REQUIRED, 'Path to project configuration file'),
3535
new InputOption('autoload-file', 'a', InputOption::VALUE_REQUIRED, 'Project\'s additional autoload file path'),
36-
new InputOption('debug', null, InputOption::VALUE_NONE, 'Show debug information - which file is analysed, do not catch internal errors'),
37-
new InputOption('memory-limit', null, InputOption::VALUE_REQUIRED, 'Memory limit for clearing result cache'),
38-
new InputOption('xdebug', null, InputOption::VALUE_NONE, 'Allow running with Xdebug for debugging purposes'),
36+
new InputOption('debug', mode: InputOption::VALUE_NONE, description: 'Show debug information - which file is analysed, do not catch internal errors'),
37+
new InputOption('memory-limit', mode: InputOption::VALUE_REQUIRED, description: 'Memory limit for clearing result cache'),
38+
new InputOption('xdebug', mode: InputOption::VALUE_NONE, description: 'Allow running with Xdebug for debugging purposes'),
3939
]);
4040
}
4141

0 commit comments

Comments
 (0)