@@ -34,16 +34,22 @@ public function __construct(
3434 $ this ->printer = $ printer ;
3535 }
3636
37- protected function configure ()
37+ protected function configure (): void
3838 {
3939 $ this ->setName ('extract ' );
4040 }
4141
4242 protected function execute (InputInterface $ input , OutputInterface $ output ): int
4343 {
4444 $ ourStubsDir = realpath (__DIR__ . '/../stubs ' );
45+ if ($ ourStubsDir === false ) {
46+ throw new \LogicException ('Invalid stubs path ' );
47+ }
4548 $ this ->clearOldStubs ($ ourStubsDir );
4649 $ srcDir = realpath (__DIR__ . '/../php-src ' );
50+ if ($ srcDir === false ) {
51+ throw new \LogicException ('Invalid php-src path ' );
52+ }
4753 $ finder = new Finder ();
4854 $ finder ->files ()->in ($ srcDir )->name ('*.stub.php ' )
4955 ->exclude ('ext/skeleton ' );
@@ -134,6 +140,8 @@ public function enterNode(Node $node)
134140 } else {
135141 throw new \Exception (sprintf ('Unhandled node type %s in %s on line %s. ' , get_class ($ node ), $ this ->stubPath , $ node ->getLine ()));
136142 }
143+
144+ return null ;
137145 }
138146
139147 /**
@@ -146,23 +154,33 @@ public function getStmts(): array
146154 };
147155
148156 $ nodeTraverser ->addVisitor ($ visitor );
149- $ nodeTraverser ->traverse ($ this ->parser ->parse (file_get_contents ($ stubPath )));
157+
158+ $ stubContents = file_get_contents ($ stubPath );
159+ if ($ stubContents === false ) {
160+ throw new \LogicException ('Could not read stub ' );
161+ }
162+ $ ast = $ this ->parser ->parse ($ stubContents );
163+ if ($ ast === null ) {
164+ throw new \LogicException ('AST cannot be null ' );
165+ }
166+ $ nodeTraverser ->traverse ($ ast );
150167
151168 $ stmts = $ visitor ->getStmts ();
152169 $ classes = [];
153170 $ functions = [];
154171 foreach ($ stmts as $ stmt ) {
172+ if (!$ stmt instanceof Node \Stmt \Class_ && !$ stmt instanceof Node \Stmt \Interface_ && !$ stmt instanceof Node \Stmt \Trait_ && !$ stmt instanceof Node \Stmt \Function_) {
173+ throw new \Exception (sprintf ('Unhandled node type %s in %s on line %s. ' , get_class ($ stmt ), $ stubPath , $ stmt ->getLine ()));
174+ }
155175 $ namespacedName = $ stmt ->namespacedName ->toString ();
156176 $ pathPart = 'stubs/ ' . dirname ($ relativeStubPath ) . '/ ' . str_replace ('\\' , '/ ' , $ namespacedName ) . '.php ' ;
157177 $ targetStubPath = __DIR__ . '/../ ' . $ pathPart ;
158178
159179 if ($ stmt instanceof Node \Stmt \Class_ || $ stmt instanceof Node \Stmt \Interface_ || $ stmt instanceof Node \Stmt \Trait_) {
160180 $ classes [strtolower ($ namespacedName )] = $ pathPart ;
161181 $ stmt = $ this ->filterClassPhpDocs ($ stmt );
162- } elseif ($ stmt instanceof Node \Stmt \Function_) {
163- $ functions [strtolower ($ namespacedName )] = $ pathPart ;
164182 } else {
165- throw new \ Exception ( sprintf ( ' Unhandled node type %s in %s on line %s. ' , get_class ( $ stmt ), $ stubPath , $ stmt -> getLine ())) ;
183+ $ functions [ strtolower ( $ namespacedName )] = $ pathPart ;
166184 }
167185
168186 if (strpos ($ namespacedName , '\\' ) !== false ) {
@@ -228,7 +246,7 @@ class Php8StubsMap
228246{
229247
230248 public const CLASSES = %s;
231-
249+
232250 public const FUNCTIONS = %s;
233251
234252}
0 commit comments