1
1
#!/usr/bin/env php
2
- <?php declare (strict_types= 1 );
2
+ <?php declare (strict_types = 1 );
3
3
4
+ use JetBrains \PhpStorm \Pure ;
4
5
use PhpParser \Node ;
5
6
use PhpParser \NodeTraverser ;
6
7
use PhpParser \NodeVisitor \NameResolver ;
7
8
use PhpParser \NodeVisitor \NodeConnectingVisitor ;
9
+ use PhpParser \NodeVisitorAbstract ;
8
10
use PhpParser \ParserFactory ;
11
+ use PHPStan \File \FileReader ;
12
+ use PHPStan \File \FileWriter ;
13
+ use PHPStan \ShouldNotHappenException ;
9
14
10
- (function () {
15
+ (function (): void {
11
16
require_once __DIR__ . '/../vendor/autoload.php ' ;
12
17
13
18
$ parser = (new ParserFactory ())->create (ParserFactory::ONLY_PHP7 );
14
19
$ finder = new Symfony \Component \Finder \Finder ();
15
20
$ finder ->in (__DIR__ . '/../vendor/jetbrains/phpstorm-stubs ' )->files ()->name ('*.php ' );
16
21
17
- $ visitor = new class () extends \ PhpParser \ NodeVisitorAbstract {
22
+ $ visitor = new class () extends NodeVisitorAbstract {
18
23
19
24
/** @var string[] */
20
- public $ functions = [];
25
+ public array $ functions = [];
21
26
22
27
/** @var string[] */
23
- public $ methods = [];
28
+ public array $ methods = [];
24
29
25
30
public function enterNode (Node $ node )
26
31
{
27
32
if ($ node instanceof Node \Stmt \Function_) {
28
33
foreach ($ node ->attrGroups as $ attrGroup ) {
29
34
foreach ($ attrGroup ->attrs as $ attr ) {
30
- if ($ attr ->name ->toString () === \ JetBrains \ PhpStorm \ Pure::class) {
35
+ if ($ attr ->name ->toString () === Pure::class) {
31
36
$ this ->functions [] = $ node ->namespacedName ->toLowerString ();
32
37
break 2 ;
33
38
}
@@ -38,12 +43,12 @@ public function enterNode(Node $node)
38
43
if ($ node instanceof Node \Stmt \ClassMethod) {
39
44
$ class = $ node ->getAttribute ('parent ' );
40
45
if (!$ class instanceof Node \Stmt \ClassLike) {
41
- throw new \ PHPStan \ ShouldNotHappenException ($ node ->name ->toString ());
46
+ throw new ShouldNotHappenException ($ node ->name ->toString ());
42
47
}
43
48
$ className = $ class ->namespacedName ->toString ();
44
49
foreach ($ node ->attrGroups as $ attrGroup ) {
45
50
foreach ($ attrGroup ->attrs as $ attr ) {
46
- if ($ attr ->name ->toString () === \ JetBrains \ PhpStorm \ Pure::class) {
51
+ if ($ attr ->name ->toString () === Pure::class) {
47
52
$ this ->methods [] = sprintf ('%s::%s ' , $ className , $ node ->name ->toString ());
48
53
break 2 ;
49
54
}
@@ -53,6 +58,7 @@ public function enterNode(Node $node)
53
58
54
59
return null ;
55
60
}
61
+
56
62
};
57
63
58
64
foreach ($ finder as $ stubFile ) {
@@ -63,7 +69,7 @@ public function enterNode(Node $node)
63
69
$ traverser ->addVisitor ($ visitor );
64
70
65
71
$ traverser ->traverse (
66
- $ parser ->parse (\ PHPStan \ File \ FileReader::read ($ path ))
72
+ $ parser ->parse (FileReader::read ($ path )),
67
73
);
68
74
}
69
75
@@ -79,7 +85,7 @@ public function enterNode(Node $node)
79
85
], true )) {
80
86
continue ;
81
87
}
82
- throw new \ PHPStan \ ShouldNotHappenException ($ functionName );
88
+ throw new ShouldNotHappenException ($ functionName );
83
89
}
84
90
}
85
91
$ metadata [$ functionName ] = ['hasSideEffects ' => false ];
@@ -88,7 +94,7 @@ public function enterNode(Node $node)
88
94
foreach ($ visitor ->methods as $ methodName ) {
89
95
if (array_key_exists ($ methodName , $ metadata )) {
90
96
if ($ metadata [$ methodName ]['hasSideEffects ' ]) {
91
- throw new \ PHPStan \ ShouldNotHappenException ($ methodName );
97
+ throw new ShouldNotHappenException ($ methodName );
92
98
}
93
99
}
94
100
$ metadata [$ methodName ] = ['hasSideEffects ' => false ];
@@ -127,6 +133,5 @@ public function enterNode(Node $node)
127
133
);
128
134
}
129
135
130
- \PHPStan \File \FileWriter::write (__DIR__ . '/../resources/functionMetadata.php ' , sprintf ($ template , $ content ));
131
-
136
+ FileWriter::write (__DIR__ . '/../resources/functionMetadata.php ' , sprintf ($ template , $ content ));
132
137
})();
0 commit comments