@@ -60,25 +60,33 @@ public function __construct($message, array $trace, $file)
6060 }
6161
6262 $ this ->trace = $ trace ;
63-
64- if ('trigger_error ' === ($ trace [1 ]['function ' ] ?? null )
65- && (DebugClassLoader::class === ($ class = $ trace [2 ]['class ' ] ?? null ) || LegacyDebugClassLoader::class === $ class )
66- && 'checkClass ' === ($ trace [2 ]['function ' ] ?? null )
67- && null !== ($ extraFile = $ 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-
7563 $ 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 ])) {
7867 // No-op
7968 }
80- $ line = $ this ->trace [$ i ];
69+
70+ $ line = $ trace [$ i ];
8171 $ 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+
8290 if (isset ($ line ['object ' ]) || isset ($ line ['class ' ])) {
8391 set_error_handler (function () {});
8492 $ parsedMsg = unserialize ($ this ->message );
@@ -101,12 +109,19 @@ public function __construct($message, array $trace, $file)
101109 return ;
102110 }
103111
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+
105116 return ;
106117 }
107118
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+ }
110125 }
111126 }
112127
@@ -140,7 +155,9 @@ public function originatingClass()
140155 throw new \LogicException ('Check with originatesFromAnObject() before calling this method. ' );
141156 }
142157
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 ;
144161 }
145162
146163 /**
@@ -168,8 +185,7 @@ public function getMessage()
168185 */
169186 public function isLegacy ()
170187 {
171- $ class = $ this ->originatingClass ();
172- if ((new \ReflectionClass ($ class ))->isInternal ()) {
188+ if (!$ this ->originClass || (new \ReflectionClass ($ this ->originClass ))->isInternal ()) {
173189 return false ;
174190 }
175191
@@ -178,8 +194,8 @@ public function isLegacy()
178194 return 0 === strpos ($ method , 'testLegacy ' )
179195 || 0 === strpos ($ method , 'provideLegacy ' )
180196 || 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 );
183199 }
184200
185201 /**
@@ -205,11 +221,10 @@ public function isMuted()
205221 */
206222 public function getType ()
207223 {
208- $ triggeringFilePathType = $ this ->getPathType ($ this ->triggeringFile );
209- if (self ::PATH_TYPE_SELF === $ triggeringFilePathType ) {
224+ if (self ::PATH_TYPE_SELF === $ pathType = $ this ->getPathType ($ this ->triggeringFile )) {
210225 return self ::TYPE_SELF ;
211226 }
212- if (self ::PATH_TYPE_UNDETERMINED === $ triggeringFilePathType ) {
227+ if (self ::PATH_TYPE_UNDETERMINED === $ pathType ) {
213228 return self ::TYPE_UNDETERMINED ;
214229 }
215230 $ erroringFile = $ erroringPackage = null ;
@@ -218,10 +233,10 @@ public function getType()
218233 if ('- ' === $ file || 'Standard input code ' === $ file || !realpath ($ file )) {
219234 continue ;
220235 }
221- if (self ::PATH_TYPE_SELF === $ this ->getPathType ($ file )) {
236+ if (self ::PATH_TYPE_SELF === $ pathType = $ this ->getPathType ($ file )) {
222237 return self ::TYPE_DIRECT ;
223238 }
224- if (self ::PATH_TYPE_UNDETERMINED === $ this -> getPathType ( $ file ) ) {
239+ if (self ::PATH_TYPE_UNDETERMINED === $ pathType ) {
225240 return self ::TYPE_UNDETERMINED ;
226241 }
227242 if (null !== $ erroringFile && null !== $ erroringPackage ) {
@@ -243,7 +258,7 @@ private function getOriginalFilesStack()
243258 if (null === $ this ->originalFilesStack ) {
244259 $ this ->originalFilesStack = [];
245260 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 ) )) {
247262 continue ;
248263 }
249264
@@ -269,13 +284,10 @@ private function getPackage($path)
269284 $ relativePath = substr ($ path , \strlen ($ vendorRoot ) + 1 );
270285 $ vendor = strstr ($ relativePath , \DIRECTORY_SEPARATOR , true );
271286 if (false === $ vendor ) {
272- throw new \ RuntimeException ( sprintf ( ' Could not find directory separator "%s" in path "%s". ' , \ DIRECTORY_SEPARATOR , $ relativePath )) ;
287+ return ' symfony ' ;
273288 }
274289
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 ), '/ ' );
279291 }
280292 }
281293
@@ -289,6 +301,13 @@ private static function getVendors()
289301 {
290302 if (null === self ::$ vendors ) {
291303 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+ }
292311 foreach (get_declared_classes () as $ class ) {
293312 if ('C ' === $ class [0 ] && 0 === strpos ($ class , 'ComposerAutoloaderInit ' )) {
294313 $ r = new \ReflectionClass ($ class );
@@ -364,10 +383,9 @@ public function toString()
364383 $ reflection ->setAccessible (true );
365384 $ reflection ->setValue ($ exception , $ this ->trace );
366385
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" ;
372390 }
373391}
0 commit comments