Repository navigation
More rules are missing named arguments #7040
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
693f39f
GetTemplateTypeRule is missing named arguments
staabm 0f6682d
NonexistentOffsetInArrayDimFetchRule is missing named arguments
staabm bc64657
ImpossibleInArrayHaystackFiniteTypesRule is missing named arguments
staabm 2cb886b
Simplify type retrieval
staabm bcf8614
add regression test
staabm edf63b7
Revert "Simplify type retrieval"
staabm a0389f0
revert unnecessary changes
staabm fb0317a
kill mutants
staabm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -4,12 +4,14 @@ | |
|
|
||
| use PhpParser\Node; | ||
| use PhpParser\Node\Expr\FuncCall; | ||
| use PHPStan\Analyser\ArgumentsNormalizer; | ||
| use PHPStan\Analyser\Scope; | ||
| use PHPStan\DependencyInjection\AutowiredParameter; | ||
| use PHPStan\DependencyInjection\Conditional; | ||
| use PHPStan\DependencyInjection\RegisteredRule; | ||
| use PHPStan\Php\PhpVersions; | ||
| use PHPStan\Reflection\InitializerExprTypeResolver; | ||
| use PHPStan\Reflection\ParametersAcceptorSelector; | ||
| use PHPStan\Reflection\ReflectionProvider; | ||
| use PHPStan\Rules\IdentifierRuleError; | ||
| use PHPStan\Rules\Rule; | ||
|
|
@@ -23,7 +25,6 @@ | |
| use function array_unique; | ||
| use function array_values; | ||
| use function count; | ||
| use function max; | ||
| use function sprintf; | ||
| use function strtolower; | ||
|
|
||
|
|
@@ -69,29 +70,48 @@ | |
| return []; | ||
| } | ||
|
|
||
| $functionName = strtolower((string) $this->reflectionProvider->resolveFunctionName($node->name, $scope)); | ||
| if (!array_key_exists($functionName, self::FUNCTIONS)) { | ||
| if (!$this->reflectionProvider->hasFunction($node->name, $scope)) { | ||
| return []; | ||
| } | ||
|
|
||
| $needleArg = self::FUNCTIONS[$functionName]['needle']; | ||
| $haystackArg = self::FUNCTIONS[$functionName]['haystack']; | ||
| $functionReflection = $this->reflectionProvider->getFunction($node->name, $scope); | ||
| $functionName = strtolower($functionReflection->getName()); | ||
| if (!array_key_exists($functionName, self::FUNCTIONS)) { | ||
| return []; | ||
| } | ||
|
|
||
| $args = $node->getArgs(); | ||
| if (count($args) <= max($needleArg, $haystackArg)) { | ||
| $parametersAcceptor = ParametersAcceptorSelector::selectFromArgs( | ||
| $scope, | ||
| $args, | ||
| $functionReflection->getVariants(), | ||
| $functionReflection->getNamedArgumentsVariants(), | ||
| ); | ||
| $normalizedFuncCall = ArgumentsNormalizer::reorderFuncArguments($parametersAcceptor, $node); | ||
| if ($normalizedFuncCall === null) { | ||
| return []; | ||
| } | ||
|
|
||
| $normalizedArgs = $normalizedFuncCall->getArgs(); | ||
| $needlePosition = self::FUNCTIONS[$functionName]['needle']; | ||
| $haystackPosition = self::FUNCTIONS[$functionName]['haystack']; | ||
| $needleArg = $normalizedArgs[$needlePosition] ?? null; | ||
| $haystackArg = $normalizedArgs[$haystackPosition] ?? null; | ||
| if ($needleArg === null || $haystackArg === null) { | ||
| return []; | ||
| } | ||
|
|
||
| $needleType = $this->treatPhpDocTypesAsCertain ? $scope->getType($args[$needleArg]->value) : $scope->getNativeType($args[$needleArg]->value); | ||
| $haystackType = $this->treatPhpDocTypesAsCertain ? $scope->getType($args[$haystackArg]->value) : $scope->getNativeType($args[$haystackArg]->value); | ||
| $needleType = $this->treatPhpDocTypesAsCertain ? $scope->getType($needleArg->value) : $scope->getNativeType($needleArg->value); | ||
| $haystackType = $this->treatPhpDocTypesAsCertain ? $scope->getType($haystackArg->value) : $scope->getNativeType($haystackArg->value); | ||
|
|
||
| $constantArrays = $haystackType->getConstantArrays(); | ||
| if (count($constantArrays) === 0) { | ||
| return []; | ||
| } | ||
|
|
||
| $isStrict = count($args) >= 3 | ||
| ? ($this->treatPhpDocTypesAsCertain ? $scope->getType($args[2]->value) : $scope->getNativeType($args[2]->value))->isTrue() | ||
| $strictArg = $normalizedArgs[2] ?? null; | ||
| $isStrict = $strictArg !== null | ||
| ? ($this->treatPhpDocTypesAsCertain ? $scope->getType($strictArg->value) : $scope->getNativeType($strictArg->value))->isTrue() | ||
|
Check warning on line 114 in src/Rules/Comparison/ImpossibleInArrayHaystackFiniteTypesRule.php
|
||
| : TrinaryLogic::createNo(); | ||
|
|
||
| /** @var array<string, array{Type, list<string>, bool}> $deadValueTypes */ | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.