|
4 | 4 |
|
5 | 5 | use PhpParser\Node; |
6 | 6 | use PhpParser\Node\Expr\StaticCall; |
| 7 | +use PHPStan\Analyser\ArgumentsNormalizer; |
7 | 8 | use PHPStan\Analyser\Scope; |
8 | 9 | use PHPStan\DependencyInjection\AutowiredService; |
9 | 10 | use PHPStan\PhpDoc\TypeStringResolver; |
@@ -46,25 +47,42 @@ public function processNode(Node $node, Scope $scope): array |
46 | 47 | return []; |
47 | 48 | } |
48 | 49 |
|
49 | | - if (!$this->reflectionProvider->hasFunction($node->name, $scope)) { |
50 | | - return []; |
51 | | - } |
52 | | - |
53 | | - $function = $this->reflectionProvider->getFunction($node->name, $scope); |
54 | | - if ($function->getName() === 'PHPStan\\Testing\\assertType') { |
55 | | - return $this->processAssertType($node->getArgs(), $scope); |
56 | | - } |
57 | | - |
58 | | - if ($function->getName() === 'PHPStan\\Testing\\assertNativeType') { |
59 | | - return $this->processAssertNativeType($node->getArgs(), $scope); |
60 | | - } |
61 | | - |
62 | | - if ($function->getName() === 'PHPStan\\Testing\\assertSuperType') { |
63 | | - return $this->processAssertSuperType($node->getArgs(), $scope); |
64 | | - } |
65 | | - |
66 | | - if ($function->getName() === 'PHPStan\\Testing\\assertVariableCertainty') { |
67 | | - return $this->processAssertVariableCertainty($node->getArgs(), $scope); |
| 50 | + $name = $this->reflectionProvider->resolveFunctionName($node->name, $scope); |
| 51 | + $args = $node->getArgs(); |
| 52 | + if ($name === 'PHPStan\\Testing\\assertType') { |
| 53 | + $typeArg = ArgumentsNormalizer::getArgByPositionOrName($args, 0, 'type'); |
| 54 | + $valueArg = ArgumentsNormalizer::getArgByPositionOrName($args, 1, 'value'); |
| 55 | + if ($typeArg === null || $valueArg === null) { |
| 56 | + return []; |
| 57 | + } |
| 58 | + return $this->processAssertType([$typeArg, $valueArg], $scope); |
| 59 | + } |
| 60 | + |
| 61 | + if ($name === 'PHPStan\\Testing\\assertNativeType') { |
| 62 | + $typeArg = ArgumentsNormalizer::getArgByPositionOrName($args, 0, 'type'); |
| 63 | + $valueArg = ArgumentsNormalizer::getArgByPositionOrName($args, 1, 'value'); |
| 64 | + if ($typeArg === null || $valueArg === null) { |
| 65 | + return []; |
| 66 | + } |
| 67 | + return $this->processAssertNativeType([$typeArg, $valueArg], $scope); |
| 68 | + } |
| 69 | + |
| 70 | + if ($name === 'PHPStan\\Testing\\assertSuperType') { |
| 71 | + $typeArg = ArgumentsNormalizer::getArgByPositionOrName($args, 0, 'superType'); |
| 72 | + $valueArg = ArgumentsNormalizer::getArgByPositionOrName($args, 1, 'value'); |
| 73 | + if ($typeArg === null || $valueArg === null) { |
| 74 | + return []; |
| 75 | + } |
| 76 | + return $this->processAssertSuperType([$typeArg, $valueArg], $scope); |
| 77 | + } |
| 78 | + |
| 79 | + if ($name === 'PHPStan\\Testing\\assertVariableCertainty') { |
| 80 | + $certaintyArg = ArgumentsNormalizer::getArgByPositionOrName($args, 0, 'certainty'); |
| 81 | + $variableArg = ArgumentsNormalizer::getArgByPositionOrName($args, 1, 'variable'); |
| 82 | + if ($certaintyArg === null || $variableArg === null) { |
| 83 | + return []; |
| 84 | + } |
| 85 | + return $this->processAssertVariableCertainty([$certaintyArg, $variableArg], $scope); |
68 | 86 | } |
69 | 87 |
|
70 | 88 | return []; |
|
0 commit comments