-
-
Notifications
You must be signed in to change notification settings - Fork 440
Expand file tree
/
Copy pathVariadicAnalyzer.php
More file actions
42 lines (34 loc) · 1.18 KB
/
VariadicAnalyzer.php
File metadata and controls
42 lines (34 loc) · 1.18 KB
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
<?php
declare(strict_types=1);
namespace Rector\NodeAnalyzer;
use PhpParser\Node\Expr\FuncCall;
use PhpParser\Node\Expr\MethodCall;
use PhpParser\Node\Expr\StaticCall;
use PHPStan\Reflection\FunctionReflection;
use PHPStan\Reflection\MethodReflection;
use Rector\Reflection\ReflectionResolver;
final readonly class VariadicAnalyzer
{
public function __construct(
private ReflectionResolver $reflectionResolver
) {
}
public function hasVariadicParameters(FuncCall | StaticCall | MethodCall $call): bool
{
$functionLikeReflection = $this->reflectionResolver->resolveFunctionLikeReflectionFromCall($call);
if ($functionLikeReflection === null) {
return false;
}
return $this->hasVariadicVariant($functionLikeReflection);
}
private function hasVariadicVariant(MethodReflection | FunctionReflection $functionLikeReflection): bool
{
foreach ($functionLikeReflection->getVariants() as $parametersAcceptor) {
// can be any number of arguments → nothing to limit here
if ($parametersAcceptor->isVariadic()) {
return true;
}
}
return false;
}
}