-
Notifications
You must be signed in to change notification settings - Fork 65
Expand file tree
/
Copy pathPropertyFetchUsageFinder.php
More file actions
51 lines (40 loc) · 1.3 KB
/
PropertyFetchUsageFinder.php
File metadata and controls
51 lines (40 loc) · 1.3 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
43
44
45
46
47
48
49
50
51
<?php
declare(strict_types=1);
namespace Rector\PHPUnit\CodeQuality\NodeFinder;
use PhpParser\Node\Expr\New_;
use PhpParser\Node\Expr\PropertyFetch;
use PhpParser\Node\Stmt\Class_;
use Rector\NodeNameResolver\NodeNameResolver;
use Rector\PhpParser\Node\BetterNodeFinder;
final readonly class PropertyFetchUsageFinder
{
public function __construct(
private NodeNameResolver $nodeNameResolver,
private BetterNodeFinder $betterNodeFinder,
) {
}
/**
* @return PropertyFetch[]
*/
public function findInNew(Class_ $class, string $propertyName): array
{
/** @var New_[] $news */
$news = $this->betterNodeFinder->findInstancesOfScoped($class->getMethods(), New_::class);
$propertyFetchesInNewArgs = [];
foreach ($news as $new) {
if ($new->isFirstClassCallable()) {
continue;
}
foreach ($new->getArgs() as $arg) {
if (! $arg->value instanceof PropertyFetch) {
continue;
}
if (! $this->nodeNameResolver->isName($arg->value->name, $propertyName)) {
continue;
}
$propertyFetchesInNewArgs[] = $arg->value;
}
}
return $propertyFetchesInNewArgs;
}
}