forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
/
FunctionSignatureVarianceRule.php
48 lines (39 loc) · 1.11 KB
/
FunctionSignatureVarianceRule.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
<?php declare(strict_types = 1);
namespace PHPStan\Rules\Generics;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Internal\SprintfHelper;
use PHPStan\Node\InFunctionNode;
use PHPStan\Reflection\ParametersAcceptorSelector;
use PHPStan\Rules\Rule;
use function sprintf;
/**
* @implements Rule<InFunctionNode>
*/
class FunctionSignatureVarianceRule implements Rule
{
public function __construct(private VarianceCheck $varianceCheck)
{
}
public function getNodeType(): string
{
return InFunctionNode::class;
}
public function processNode(Node $node, Scope $scope): array
{
$functionReflection = $scope->getFunction();
if ($functionReflection === null) {
return [];
}
$functionName = $functionReflection->getName();
return $this->varianceCheck->checkParametersAcceptor(
ParametersAcceptorSelector::selectSingle($functionReflection->getVariants()),
sprintf('in parameter %%s of function %s()', SprintfHelper::escapeFormatString($functionName)),
sprintf('in return type of function %s()', $functionName),
sprintf('in function %s()', $functionName),
false,
false,
false,
);
}
}