@@ -44,25 +44,27 @@ public static function getImports(object $target): array
44
44
$ count = 0 ;
45
45
$ trace = debug_backtrace ();
46
46
foreach ($ trace as $ info ) {
47
- $ class = $ info ['class ' ] ?? null ;
48
- $ function = $ info ['function ' ] ?? null ;
49
- // Looking for the file where the target calls the method __call().
50
- if ($ class == get_class ($ target ) && $ function == '__call ' ) {
51
- $ file = $ info ['file ' ] ?? '' ;
52
- break ;
47
+ $ object = $ info ['object ' ] ?? null ;
48
+ if ($ object ) {
49
+ // Looking for the file where the target object calls the method __call().
50
+ $ function = $ info ['function ' ] ?? null ;
51
+ if ($ object ::class == $ target ::class && $ function == '__call ' ) {
52
+ $ file = $ info ['file ' ] ?? '' ;
53
+ break ;
54
+ }
53
55
}
54
56
$ count ++;
55
57
}
56
58
57
- $ classes = self ::$ classes [$ file ] ?? [];
59
+ $ classes = static ::$ classes [$ file ] ?? [];
58
60
// Return the imports if they are already stored.
59
61
if ($ classes ) return $ classes ;
60
62
61
63
// Add the case where the extension method used inside the extension class.
62
64
$ callerClass = $ trace [$ count + 1 ]['class ' ] ?? null ;
63
65
if ($ callerClass ) {
64
66
$ classes [] = $ callerClass ;
65
- self ::$ classes [$ file ] = $ classes ;
67
+ static ::$ classes [$ file ] = $ classes ;
66
68
}
67
69
68
70
// Looking for all the imports in the file.
@@ -71,7 +73,7 @@ public static function getImports(object $target): array
71
73
preg_match_all ("%(?i)use\s+([A-Za-z_ \\\]+);% " , $ contents , $ matches );
72
74
if (isset ($ matches [1 ])) {
73
75
$ classes = array_merge ($ classes , $ matches [1 ]);
74
- self ::$ classes [$ file ] = $ classes ;
76
+ static ::$ classes [$ file ] = $ classes ;
75
77
}
76
78
}
77
79
0 commit comments