forked from phpstan/phpstan-src
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathArrayFindArgVisitor.php
More file actions
32 lines (26 loc) · 813 Bytes
/
Copy pathArrayFindArgVisitor.php
File metadata and controls
32 lines (26 loc) · 813 Bytes
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
<?php declare(strict_types = 1);
namespace PHPStan\Parser;
use Override;
use PhpParser\Node;
use PhpParser\NodeVisitorAbstract;
use PHPStan\DependencyInjection\AutowiredService;
use function in_array;
#[AutowiredService]
final class ArrayFindArgVisitor extends NodeVisitorAbstract
{
public const ATTRIBUTE_NAME = 'isArrayFindArg';
#[Override]
public function enterNode(Node $node): ?Node
{
if ($node instanceof Node\Expr\FuncCall && $node->name instanceof Node\Name && !$node->isFirstClassCallable()) {
$functionName = $node->name->toLowerString();
if (in_array($functionName, ['array_all', 'array_any', 'array_find', 'array_find_key'], true)) {
$args = $node->getArgs();
if (isset($args[0])) {
$args[0]->setAttribute(self::ATTRIBUTE_NAME, true);
}
}
}
return null;
}
}