Skip to content

Commit 9ad1d27

Browse files
committed
[Debug] Correctly detect methods not from the same vendor
1 parent 1a9a254 commit 9ad1d27

File tree

2 files changed

+24
-13
lines changed

2 files changed

+24
-13
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

+18-9
Original file line numberDiff line numberDiff line change
@@ -232,19 +232,28 @@ public function loadClass($class)
232232
continue;
233233
}
234234

235+
// Method from a trait
236+
if ($method->getFilename() !== $refl->getFileName()) {
237+
continue;
238+
}
239+
235240
if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
236-
list($methodShortName, $message) = self::$finalMethods[$parent][$method->name];
237-
@trigger_error(sprintf('The "%s" method is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $methodShortName, $message, $name), E_USER_DEPRECATED);
241+
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
242+
@trigger_error(sprintf('The "%s::%s()" method is considered final%s. It may change without further notice as of its next major version. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
238243
}
239244

240245
foreach ($parentAndTraits as $use) {
241-
if (isset(self::$deprecatedMethods[$use][$method->name]) && strncmp($ns, $use, $len)) {
242-
list($methodShortName, $message) = self::$deprecatedMethods[$use][$method->name];
243-
@trigger_error(sprintf('The "%s" method is deprecated%s. You should not extend it from "%s".', $methodShortName, $message, $name), E_USER_DEPRECATED);
246+
if (isset(self::$deprecatedMethods[$use][$method->name])) {
247+
list($declaringClass, $message) = self::$deprecatedMethods[$use][$method->name];
248+
if (strncmp($ns, $declaringClass, $len)) {
249+
@trigger_error(sprintf('The "%s::%s()" method is deprecated%s. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
250+
}
244251
}
245-
if (isset(self::$internalMethods[$use][$method->name]) && strncmp($ns, $use, $len)) {
246-
list($methodShortName, $message) = self::$internalMethods[$use][$method->name];
247-
@trigger_error(sprintf('The "%s" method is considered internal%s. It may change without further notice. You should not use it from "%s".', $methodShortName, $message, $name), E_USER_DEPRECATED);
252+
if (isset(self::$internalMethods[$use][$method->name])) {
253+
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
254+
if (strncmp($ns, $declaringClass, $len)) {
255+
@trigger_error(sprintf('The "%s::%s()" method is considered internal%s. It may change without further notice. You should not extend it from "%s".', $declaringClass, $method->name, $message, $name), E_USER_DEPRECATED);
256+
}
248257
}
249258
}
250259

@@ -256,7 +265,7 @@ public function loadClass($class)
256265
foreach (array('final', 'deprecated', 'internal') as $annotation) {
257266
if (false !== strpos($doc, '@'.$annotation) && preg_match('#\n\s+\* @'.$annotation.'(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
258267
$message = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
259-
self::${$annotation.'Methods'}[$name][$method->name] = array(sprintf('%s::%s()', $name, $method->name), $message);
268+
self::${$annotation.'Methods'}[$name][$method->name] = array($name, $message);
260269
}
261270
}
262271
}

src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php

+6-4
Original file line numberDiff line numberDiff line change
@@ -347,10 +347,10 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsInternals', true);
347347
restore_error_handler();
348348

349349
$this->assertSame($deprecations, array(
350+
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal since version 3.4. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".',
351+
'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternalsParent".',
350352
'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait" trait is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
351-
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass" class is considered internal since version 3.4. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
352-
'The "Symfony\Component\Debug\Tests\Fixtures\InternalInterface" interface is considered internal. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
353-
'The "Symfony\Component\Debug\Tests\Fixtures\InternalClass::internalMethod()" method is considered internal since version 3.4. It may change without further notice. You should not use it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
353+
'The "Symfony\Component\Debug\Tests\Fixtures\InternalTrait2::internalMethod()" method is considered internal since version 3.4. It may change without further notice. You should not extend it from "Test\Symfony\Component\Debug\Tests\ExtendsInternals".',
354354
));
355355
}
356356
}
@@ -399,11 +399,13 @@ public function findFile($class)
399399
public function deprecatedMethod() { }
400400
}');
401401
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternals' === $class) {
402-
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface {
402+
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternals extends ExtendsInternalsParent {
403403
use \\'.__NAMESPACE__.'\Fixtures\InternalTrait;
404404
405405
public function internalMethod() { }
406406
}');
407+
} elseif ('Test\\'.__NAMESPACE__.'\ExtendsInternalsParent' === $class) {
408+
eval('namespace Test\\'.__NAMESPACE__.'; class ExtendsInternalsParent extends \\'.__NAMESPACE__.'\Fixtures\InternalClass implements \\'.__NAMESPACE__.'\Fixtures\InternalInterface { }');
407409
}
408410
}
409411
}

0 commit comments

Comments
 (0)