Skip to content

Commit b736ddc

Browse files
committed
Modernized InFunctionNode rules
1 parent c3da6a9 commit b736ddc

6 files changed

+8
-37
lines changed

Diff for: src/Rules/Functions/ExistingClassesInTypehintsRule.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Internal\SprintfHelper;
88
use PHPStan\Node\InFunctionNode;
9-
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
109
use PHPStan\Rules\FunctionDefinitionCheck;
1110
use PHPStan\Rules\Rule;
1211
use function sprintf;
@@ -28,15 +27,11 @@ public function getNodeType(): string
2827

2928
public function processNode(Node $node, Scope $scope): array
3029
{
31-
if (!$scope->getFunction() instanceof PhpFunctionFromParserNodeReflection) {
32-
return [];
33-
}
34-
35-
$functionName = SprintfHelper::escapeFormatString($scope->getFunction()->getName());
30+
$functionName = SprintfHelper::escapeFormatString($node->getFunctionReflection()->getName());
3631

3732
return $this->check->checkFunction(
3833
$node->getOriginalNode(),
39-
$scope->getFunction(),
34+
$node->getFunctionReflection(),
4035
sprintf(
4136
'Parameter $%%s of function %s() has invalid type %%s.',
4237
$functionName,

Diff for: src/Rules/Functions/MissingFunctionParameterTypehintRule.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,6 @@
88
use PHPStan\Reflection\FunctionReflection;
99
use PHPStan\Reflection\ParameterReflection;
1010
use PHPStan\Reflection\ParametersAcceptorSelector;
11-
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
1211
use PHPStan\Rules\MissingTypehintCheck;
1312
use PHPStan\Rules\Rule;
1413
use PHPStan\Rules\RuleError;
@@ -37,11 +36,7 @@ public function getNodeType(): string
3736

3837
public function processNode(Node $node, Scope $scope): array
3938
{
40-
$functionReflection = $scope->getFunction();
41-
if (!$functionReflection instanceof PhpFunctionFromParserNodeReflection) {
42-
return [];
43-
}
44-
39+
$functionReflection = $node->getFunctionReflection();
4540
$messages = [];
4641

4742
foreach (ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getParameters() as $parameterReflection) {

Diff for: src/Rules/Functions/MissingFunctionReturnTypehintRule.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\InFunctionNode;
88
use PHPStan\Reflection\ParametersAcceptorSelector;
9-
use PHPStan\Reflection\Php\PhpFunctionFromParserNodeReflection;
109
use PHPStan\Rules\MissingTypehintCheck;
1110
use PHPStan\Rules\Rule;
1211
use PHPStan\Rules\RuleErrorBuilder;
@@ -34,11 +33,7 @@ public function getNodeType(): string
3433

3534
public function processNode(Node $node, Scope $scope): array
3635
{
37-
$functionReflection = $scope->getFunction();
38-
if (!$functionReflection instanceof PhpFunctionFromParserNodeReflection) {
39-
return [];
40-
}
41-
36+
$functionReflection = $node->getFunctionReflection();
4237
$returnType = ParametersAcceptorSelector::selectSingle($functionReflection->getVariants())->getReturnType();
4338

4439
if ($returnType instanceof MixedType && !$returnType->isExplicitMixed()) {

Diff for: src/Rules/Generics/FunctionSignatureVarianceRule.php

+1-5
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,7 @@ public function getNodeType(): string
2727

2828
public function processNode(Node $node, Scope $scope): array
2929
{
30-
$functionReflection = $scope->getFunction();
31-
if ($functionReflection === null) {
32-
return [];
33-
}
34-
30+
$functionReflection = $node->getFunctionReflection();
3531
$functionName = $functionReflection->getName();
3632

3733
return $this->varianceCheck->checkParametersAcceptor(

Diff for: src/Rules/PhpDoc/FunctionAssertRule.php

+1-6
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\InFunctionNode;
88
use PHPStan\Rules\Rule;
9-
use PHPStan\ShouldNotHappenException;
109
use function count;
1110

1211
/**
@@ -26,11 +25,7 @@ public function getNodeType(): string
2625

2726
public function processNode(Node $node, Scope $scope): array
2827
{
29-
$function = $scope->getFunction();
30-
if ($function === null) {
31-
throw new ShouldNotHappenException();
32-
}
33-
28+
$function = $node->getFunctionReflection();
3429
$variants = $function->getVariants();
3530
if (count($variants) !== 1) {
3631
return [];

Diff for: src/Rules/PhpDoc/FunctionConditionalReturnTypeRule.php

+2-7
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
use PHPStan\Analyser\Scope;
77
use PHPStan\Node\InFunctionNode;
88
use PHPStan\Rules\Rule;
9-
use PHPStan\ShouldNotHappenException;
109
use function count;
1110

1211
/**
@@ -26,12 +25,8 @@ public function getNodeType(): string
2625

2726
public function processNode(Node $node, Scope $scope): array
2827
{
29-
$method = $scope->getFunction();
30-
if ($method === null) {
31-
throw new ShouldNotHappenException();
32-
}
33-
34-
$variants = $method->getVariants();
28+
$function = $node->getFunctionReflection();
29+
$variants = $function->getVariants();
3530
if (count($variants) !== 1) {
3631
return [];
3732
}

0 commit comments

Comments
 (0)