Skip to content

Commit d144495

Browse files
authored
Remove deprecated ParametersAcceptorSelector::selectFromArgs (#272)
1 parent d35bf66 commit d144495

6 files changed

+20
-35
lines changed

composer.json

+2-2
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": "^7.4 || ^8.0",
14-
"phpstan/phpstan": "^1.11.0"
14+
"phpstan/phpstan": "^1.12.5"
1515
},
1616
"require-dev": {
1717
"editorconfig-checker/editorconfig-checker": "^10.6.0",
@@ -74,7 +74,7 @@
7474
"check:ec": "ec src tests",
7575
"check:ignores": "php bin/verify-inline-ignore.php",
7676
"check:tests": "phpunit -vvv tests",
77-
"check:types": "phpstan analyse -vvv --ansi",
77+
"check:types": "phpstan analyse -vv --ansi",
7878
"fix:cs": "phpcbf"
7979
}
8080
}

composer.lock

+6-6
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Rule/EnforceListReturnRule.php

+5-22
Original file line numberDiff line numberDiff line change
@@ -6,9 +6,7 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\ClosureReturnStatementsNode;
88
use PHPStan\Node\ReturnStatementsNode;
9-
use PHPStan\Reflection\FunctionReflection;
109
use PHPStan\Reflection\MethodReflection;
11-
use PHPStan\Reflection\ParametersAcceptorSelector;
1210
use PHPStan\Rules\IdentifierRuleError;
1311
use PHPStan\Rules\Rule;
1412
use PHPStan\Rules\RuleErrorBuilder;
@@ -43,12 +41,15 @@ public function processNode(Node $node, Scope $scope): array
4341
return [];
4442
}
4543

46-
if ($this->alwaysReturnList($node) && !$this->isMarkedWithListReturn($methodReflection)) {
44+
$returnType = $methodReflection->getReturnType();
45+
46+
if ($this->alwaysReturnList($node) && !$returnType->isList()->yes()) {
4747
$callLikeType = $methodReflection instanceof MethodReflection
4848
? 'Method'
4949
: 'Function';
50+
$returnTypeString = $returnType->describe(VerbosityLevel::precise());
5051

51-
$error = RuleErrorBuilder::message("{$callLikeType} {$methodReflection->getName()} always return list, but is marked as {$this->getReturnPhpDoc($methodReflection)}")
52+
$error = RuleErrorBuilder::message("{$callLikeType} {$methodReflection->getName()} always return list, but is marked as {$returnTypeString}")
5253
->identifier('shipmonk.returnListNotUsed')
5354
->build();
5455
return [$error];
@@ -57,15 +58,6 @@ public function processNode(Node $node, Scope $scope): array
5758
return [];
5859
}
5960

60-
/**
61-
* @param FunctionReflection|MethodReflection $methodReflection
62-
*/
63-
private function getReturnPhpDoc(object $methodReflection): string
64-
{
65-
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
66-
return $returnType->describe(VerbosityLevel::precise());
67-
}
68-
6961
private function alwaysReturnList(ReturnStatementsNode $node): bool
7062
{
7163
$returnStatementsCount = count($node->getReturnStatements());
@@ -95,13 +87,4 @@ private function alwaysReturnList(ReturnStatementsNode $node): bool
9587
return true;
9688
}
9789

98-
/**
99-
* @param FunctionReflection|MethodReflection $methodReflection
100-
*/
101-
private function isMarkedWithListReturn(object $methodReflection): bool
102-
{
103-
$returnType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
104-
return $returnType->isList()->yes();
105-
}
106-
10790
}

src/Rule/ForbidReturnValueInYieldingMethodRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Node\ClosureReturnStatementsNode;
99
use PHPStan\Node\MethodReturnStatementsNode;
1010
use PHPStan\Node\ReturnStatementsNode;
11-
use PHPStan\Reflection\ParametersAcceptorSelector;
1211
use PHPStan\Rules\IdentifierRuleError;
1312
use PHPStan\Rules\Rule;
1413
use PHPStan\Rules\RuleErrorBuilder;
@@ -90,7 +89,7 @@ private function getReturnType(ReturnStatementsNode $node, Scope $scope): Type
9089
}
9190

9291
if ($methodReflection !== null) {
93-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
92+
return $methodReflection->getReturnType();
9493
}
9594

9695
return new MixedType();

src/Rule/ForbidUselessNullableReturnRule.php

+1-2
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\ClosureReturnStatementsNode;
88
use PHPStan\Node\ReturnStatementsNode;
9-
use PHPStan\Reflection\ParametersAcceptorSelector;
109
use PHPStan\Rules\IdentifierRuleError;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
@@ -39,7 +38,7 @@ public function processNode(Node $node, Scope $scope): array
3938
if ($node instanceof ClosureReturnStatementsNode) {
4039
$declaredType = $scope->getFunctionType($node->getClosureExpr()->getReturnType(), false, false);
4140
} elseif ($methodReflection !== null) {
42-
$declaredType = ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getReturnType();
41+
$declaredType = $methodReflection->getReturnType();
4342
} else {
4443
return [];
4544
}

src/Rule/RequirePreviousExceptionPassRule.php

+5-1
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,11 @@ private function getCallLikeParameters(CallLike $node, Scope $scope): array
171171

172172
// FuncCall not yet supported
173173
if ($methodReflection !== null) {
174-
return ParametersAcceptorSelector::selectSingle($methodReflection->getVariants())->getParameters();
174+
return ParametersAcceptorSelector::selectFromArgs(
175+
$scope,
176+
$node->getArgs(),
177+
$methodReflection->getVariants(),
178+
)->getParameters();
175179
}
176180

177181
return [];

0 commit comments

Comments
 (0)