/
UsedViewFacadeMakeCollector.php
59 lines (44 loc) · 1.33 KB
/
UsedViewFacadeMakeCollector.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
49
50
51
52
53
54
55
56
57
58
59
<?php
declare(strict_types=1);
namespace NunoMaduro\Larastan\Collectors;
use Illuminate\Support\Facades\View;
use Illuminate\View\ViewName;
use PhpParser\Node;
use PHPStan\Analyser\Scope;
use PHPStan\Collectors\Collector;
use PHPStan\Type\ObjectType;
/** @implements Collector<Node\Expr\StaticCall, string> */
final class UsedViewFacadeMakeCollector implements Collector
{
public function getNodeType(): string
{
return Node\Expr\StaticCall::class;
}
/** @param Node\Expr\StaticCall $node */
public function processNode(Node $node, Scope $scope): ?string
{
$name = $node->name;
if (! $name instanceof Node\Identifier) {
return null;
}
if ($name->name !== 'make') {
return null;
}
if (count($node->getArgs()) < 1) {
return null;
}
$class = $node->class;
if (! $class instanceof Node\Name) {
return null;
}
$class = $scope->resolveName($class);
if (! (new ObjectType(View::class))->isSuperTypeOf(new ObjectType($class))->yes()) {
return null;
}
$template = $node->getArgs()[0]->value;
if (! $template instanceof Node\Scalar\String_) {
return null;
}
return ViewName::normalize($template->value);
}
}