@@ -60,25 +60,33 @@ public function __construct($message, array $trace, $file)
60
60
}
61
61
62
62
$ this ->trace = $ trace ;
63
-
64
- if ('trigger_error ' === (isset ($ trace [1 ]['function ' ]) ? $ trace [1 ]['function ' ] : null )
65
- && (DebugClassLoader::class === ($ class = (isset ($ trace [2 ]['class ' ]) ? $ trace [2 ]['class ' ] : null )) || LegacyDebugClassLoader::class === $ class )
66
- && 'checkClass ' === (isset ($ trace [2 ]['function ' ]) ? $ trace [2 ]['function ' ] : null )
67
- && null !== ($ extraFile = (isset ($ trace [2 ]['args ' ][1 ]) ? $ trace [2 ]['args ' ][1 ] : null ))
68
- && '' !== $ extraFile
69
- && false !== $ extraFile = realpath ($ extraFile )
70
- ) {
71
- $ this ->getOriginalFilesStack ();
72
- array_splice ($ this ->originalFilesStack , 2 , 1 , $ extraFile );
73
- }
74
-
75
63
$ this ->message = $ message ;
76
- $ i = \count ($ this ->trace );
77
- while (1 < $ i && $ this ->lineShouldBeSkipped ($ this ->trace [--$ i ])) {
64
+
65
+ $ i = \count ($ trace );
66
+ while (1 < $ i && $ this ->lineShouldBeSkipped ($ trace [--$ i ])) {
78
67
// No-op
79
68
}
80
- $ line = $ this ->trace [$ i ];
69
+
70
+ $ line = $ trace [$ i ];
81
71
$ this ->triggeringFile = $ file ;
72
+
73
+ for ($ j = 1 ; $ j < $ i ; ++$ j ) {
74
+ if (!isset ($ trace [$ j ]['function ' ], $ trace [1 + $ j ]['class ' ], $ trace [1 + $ j ]['args ' ][0 ])) {
75
+ continue ;
76
+ }
77
+
78
+ if ('trigger_error ' === $ trace [$ j ]['function ' ] && !isset ($ trace [$ j ]['class ' ])) {
79
+ if (\in_array ($ trace [1 + $ j ]['class ' ], [DebugClassLoader::class, LegacyDebugClassLoader::class], true )) {
80
+ $ class = $ trace [1 + $ j ]['args ' ][0 ];
81
+ $ this ->triggeringFile = isset ($ trace [1 + $ j ]['args ' ][1 ]) ? realpath ($ trace [1 + $ j ]['args ' ][1 ]) : (new \ReflectionClass ($ class ))->getFileName ();
82
+ $ this ->getOriginalFilesStack ();
83
+ array_splice ($ this ->originalFilesStack , 0 , $ j , [$ this ->triggeringFile ]);
84
+ }
85
+
86
+ break ;
87
+ }
88
+ }
89
+
82
90
if (isset ($ line ['object ' ]) || isset ($ line ['class ' ])) {
83
91
set_error_handler (function () {});
84
92
$ parsedMsg = unserialize ($ this ->message );
@@ -101,12 +109,19 @@ public function __construct($message, array $trace, $file)
101
109
return ;
102
110
}
103
111
104
- if (isset ($ line ['class ' ]) && 0 === strpos ($ line ['class ' ], SymfonyTestsListenerFor::class)) {
112
+ if (!isset ($ line ['class ' ], $ trace [$ i - 2 ]['function ' ]) || 0 !== strpos ($ line ['class ' ], SymfonyTestsListenerFor::class)) {
113
+ $ this ->originClass = isset ($ line ['object ' ]) ? \get_class ($ line ['object ' ]) : $ line ['class ' ];
114
+ $ this ->originMethod = $ line ['function ' ];
115
+
105
116
return ;
106
117
}
107
118
108
- $ this ->originClass = isset ($ line ['object ' ]) ? \get_class ($ line ['object ' ]) : $ line ['class ' ];
109
- $ this ->originMethod = $ line ['function ' ];
119
+ if ('trigger_error ' !== $ trace [$ i - 2 ]['function ' ] || isset ($ trace [$ i - 2 ]['class ' ])) {
120
+ $ this ->originClass = \get_class ($ line ['args ' ][0 ]);
121
+ $ this ->originMethod = $ line ['args ' ][0 ]->getName ();
122
+
123
+ return ;
124
+ }
110
125
}
111
126
}
112
127
@@ -140,7 +155,9 @@ public function originatingClass()
140
155
throw new \LogicException ('Check with originatesFromAnObject() before calling this method. ' );
141
156
}
142
157
143
- return $ this ->originClass ;
158
+ $ class = $ this ->originClass ;
159
+
160
+ return false !== strpos ($ class , "@anonymous \0" ) ? (get_parent_class ($ class ) ?: key (class_implements ($ class )) ?: 'class ' ).'@anonymous ' : $ class ;
144
161
}
145
162
146
163
/**
@@ -168,8 +185,7 @@ public function getMessage()
168
185
*/
169
186
public function isLegacy ()
170
187
{
171
- $ class = $ this ->originatingClass ();
172
- if ((new \ReflectionClass ($ class ))->isInternal ()) {
188
+ if (!$ this ->originClass || (new \ReflectionClass ($ this ->originClass ))->isInternal ()) {
173
189
return false ;
174
190
}
175
191
@@ -178,8 +194,8 @@ public function isLegacy()
178
194
return 0 === strpos ($ method , 'testLegacy ' )
179
195
|| 0 === strpos ($ method , 'provideLegacy ' )
180
196
|| 0 === strpos ($ method , 'getLegacy ' )
181
- || strpos ($ class , '\Legacy ' )
182
- || \in_array ('legacy ' , Test::getGroups ($ class , $ method ), true );
197
+ || strpos ($ this -> originClass , '\Legacy ' )
198
+ || \in_array ('legacy ' , Test::getGroups ($ this -> originClass , $ method ), true );
183
199
}
184
200
185
201
/**
@@ -205,11 +221,10 @@ public function isMuted()
205
221
*/
206
222
public function getType ()
207
223
{
208
- $ triggeringFilePathType = $ this ->getPathType ($ this ->triggeringFile );
209
- if (self ::PATH_TYPE_SELF === $ triggeringFilePathType ) {
224
+ if (self ::PATH_TYPE_SELF === $ pathType = $ this ->getPathType ($ this ->triggeringFile )) {
210
225
return self ::TYPE_SELF ;
211
226
}
212
- if (self ::PATH_TYPE_UNDETERMINED === $ triggeringFilePathType ) {
227
+ if (self ::PATH_TYPE_UNDETERMINED === $ pathType ) {
213
228
return self ::TYPE_UNDETERMINED ;
214
229
}
215
230
$ erroringFile = $ erroringPackage = null ;
@@ -218,10 +233,10 @@ public function getType()
218
233
if ('- ' === $ file || 'Standard input code ' === $ file || !realpath ($ file )) {
219
234
continue ;
220
235
}
221
- if (self ::PATH_TYPE_SELF === $ this ->getPathType ($ file )) {
236
+ if (self ::PATH_TYPE_SELF === $ pathType = $ this ->getPathType ($ file )) {
222
237
return self ::TYPE_DIRECT ;
223
238
}
224
- if (self ::PATH_TYPE_UNDETERMINED === $ this -> getPathType ( $ file ) ) {
239
+ if (self ::PATH_TYPE_UNDETERMINED === $ pathType ) {
225
240
return self ::TYPE_UNDETERMINED ;
226
241
}
227
242
if (null !== $ erroringFile && null !== $ erroringPackage ) {
@@ -243,7 +258,7 @@ private function getOriginalFilesStack()
243
258
if (null === $ this ->originalFilesStack ) {
244
259
$ this ->originalFilesStack = [];
245
260
foreach ($ this ->trace as $ frame ) {
246
- if (!isset ($ frame ['file ' ]) || \in_array ($ frame ['function ' ], ['require ' , 'require_once ' , 'include ' , 'include_once ' ], true )) {
261
+ if (!isset ($ frame ['file ' ], $ frame [ ' function ' ] ) || (! isset ( $ frame [ ' class ' ]) && \in_array ($ frame ['function ' ], ['require ' , 'require_once ' , 'include ' , 'include_once ' ], true ) )) {
247
262
continue ;
248
263
}
249
264
@@ -269,13 +284,10 @@ private function getPackage($path)
269
284
$ relativePath = substr ($ path , \strlen ($ vendorRoot ) + 1 );
270
285
$ vendor = strstr ($ relativePath , \DIRECTORY_SEPARATOR , true );
271
286
if (false === $ vendor ) {
272
- throw new \ RuntimeException ( sprintf ( ' Could not find directory separator "%s" in path "%s". ' , \ DIRECTORY_SEPARATOR , $ relativePath )) ;
287
+ return ' symfony ' ;
273
288
}
274
289
275
- return rtrim ($ vendor .'/ ' .strstr (substr (
276
- $ relativePath ,
277
- \strlen ($ vendor ) + 1
278
- ), \DIRECTORY_SEPARATOR , true ), '/ ' );
290
+ return rtrim ($ vendor .'/ ' .strstr (substr ($ relativePath , \strlen ($ vendor ) + 1 ), \DIRECTORY_SEPARATOR , true ), '/ ' );
279
291
}
280
292
}
281
293
@@ -289,6 +301,13 @@ private static function getVendors()
289
301
{
290
302
if (null === self ::$ vendors ) {
291
303
self ::$ vendors = $ paths = [];
304
+ self ::$ vendors [] = \dirname (__DIR__ ).\DIRECTORY_SEPARATOR .'Legacy ' ;
305
+ if (class_exists (DebugClassLoader::class, false )) {
306
+ self ::$ vendors [] = \dirname ((new \ReflectionClass (DebugClassLoader::class))->getFileName ());
307
+ }
308
+ if (class_exists (LegacyDebugClassLoader::class, false )) {
309
+ self ::$ vendors [] = \dirname ((new \ReflectionClass (LegacyDebugClassLoader::class))->getFileName ());
310
+ }
292
311
foreach (get_declared_classes () as $ class ) {
293
312
if ('C ' === $ class [0 ] && 0 === strpos ($ class , 'ComposerAutoloaderInit ' )) {
294
313
$ r = new \ReflectionClass ($ class );
@@ -364,10 +383,9 @@ public function toString()
364
383
$ reflection ->setAccessible (true );
365
384
$ reflection ->setValue ($ exception , $ this ->trace );
366
385
367
- return 'deprecation triggered by ' .$ this ->originatingClass ().':: ' .$ this ->originatingMethod ().': ' .
368
- "\n" .$ this ->message .
369
- "\nStack trace: " .
370
- "\n" .str_replace (' ' .getcwd ().\DIRECTORY_SEPARATOR , ' ' , $ exception ->getTraceAsString ()).
371
- "\n" ;
386
+ return ($ this ->originatesFromAnObject () ? 'deprecation triggered by ' .$ this ->originatingClass ().':: ' .$ this ->originatingMethod ().": \n" : '' )
387
+ .$ this ->message ."\n"
388
+ ."Stack trace: \n"
389
+ .str_replace (' ' .getcwd ().\DIRECTORY_SEPARATOR , ' ' , $ exception ->getTraceAsString ())."\n" ;
372
390
}
373
391
}
0 commit comments