File tree Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Expand file tree Collapse file tree 1 file changed +8
-3
lines changed Original file line number Diff line number Diff line change 55use PhpParser \NodeTraverser ;
66use PhpParser \ParserFactory ;
77use PhpParser \Node \Stmt \Class_ ;
8+ use PhpParser \Node \Stmt \Namespace_ ;
89use Illuminate \Support \Collection ;
910use Illuminate \Filesystem \Filesystem ;
1011use PhpParser \NodeVisitor \NameResolver ;
@@ -42,10 +43,14 @@ protected function getFullyQualifiedClassNameFromFile(string $path): string
4243 $ code = file_get_contents ($ path );
4344
4445 $ statements = $ parser ->parse ($ code );
45-
4646 $ statements = $ traverser ->traverse ($ statements );
47+
48+ // get the first namespace declaration in the file
49+ $ root_statement = collect ($ statements )->filter (function ($ statement ) {
50+ return $ statement instanceof Namespace_;
51+ })->first ();
4752
48- return collect ($ statements [ 0 ] ->stmts )
53+ return collect ($ root_statement ->stmts )
4954 ->filter (function ($ statement ) {
5055 return $ statement instanceof Class_;
5156 })
@@ -55,4 +60,4 @@ protected function getFullyQualifiedClassNameFromFile(string $path): string
5560 ->first () ?? '' ;
5661 }
5762
58- }
63+ }
You can’t perform that action at this time.
0 commit comments