8000 Try a different approach · symfony/symfony@ea53d22 · GitHub
[go: up one dir, main page]

Skip to content

Commit ea53d22

Browse files
committed
Try a different approach
1 parent ae936f8 commit ea53d22

File tree

3 files changed

+29
-24
lines changed

3 files changed

+29
-24
lines changed

src/Symfony/Component/Debug/DebugClassLoader.php

Lines changed: 21 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -174,33 +174,30 @@ public function loadClass($class)
174174
@trigger_error(sprintf('The %s class is considered final%s. It may change without further notice as of its next major version. You should not extend it from %s.', $parent, self::$final[$parent], $name), E_USER_DEPRECATED);
175175
}
176176

177-
// Only check final methods if the class has a parent
178-
if ($parent) {
179-
foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $method) {
180-
try {
181-
$prototype = $method->getPrototype();
182-
} catch (\ReflectionException $e) {
183-
continue;
184-
}
177+
// Inherit @final annotations
178+
self::$finalMethods[$name] = $parent && isset(self::$finalMethods[$parent]) ? self::$finalMethods[$parent] : array();
185179

186-
$declaringClass = $prototype->getDeclaringClass()->getName();
187-
$methodName = $method->getName();
188-
if (!isset(self::$finalMethods[$declaringClass][$methodName])) {
189-
if (!isset(self::$finalMethods[$declaringClass])) {
190-
self::$finalMethods[$declaringClass] = array();
191-
}
180+
foreach ($refl->getMethods(\ReflectionMethod::IS_PUBLIC | \ReflectionMethod::IS_PROTECTED) as $method) {
181+
// It's not the declaring class
182+
if ($method->class !== $name) {
183+
continue;
184+
}
192185

193-
if (preg_match('#\n\s+\* @final(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $prototype->getDocComment(), $notice)) {
194-
self::$finalMethods[$declaringClass][$methodName] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
195-
} else {
196-
self::$finalMethods[$declaringClass][$methodName] = false;
197-
}
198-
}
186+
if ($parent && isset(self::$finalMethods[$parent][$method->name])) {
187+
// Fetch the real class declaring the parent method
188+
$prototype = $method->getPrototype();
199189

200-
$finalMethod = self::$finalMethods[$declaringClass][$methodName];
201-
if (false !== $finalMethod) {
202-
@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, $methodName, $finalMethod, $name), E_USER_DEPRECATED);
203-
}
190+
@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.', $prototype->class, $method->name, self::$finalMethods[$parent][$method->name], $name), E_USER_DEPRECATED);
191+
}
192+
193+
$doc = $method->getDocComment();
194+
// No @final annotation
195+
if (false === $doc || false === strpos($doc, '@final')) {
196+
continue;
197+
}
198+
199+
if (preg_match('#\n\s+\* @final(?:( .+?)\.?)?\r?\n\s+\*(?: @|/$)#s', $doc, $notice)) {
200+
self::$finalMethods[$name][$method->name] = isset($notice[1]) ? preg_replace('#\s*\r?\n \* +#', ' ', $notice[1]) : '';
204201
}
205202
}
206203

src/Symfony/Component/Debug/Tests/Fixtures/ExtendedFinalMethod.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ class ExtendedFinalMethod extends FinalMethod
1010
public function finalMethod()
1111
{
1212
}
13+
14+
public function anotherMethod()
15+
{
16+
}
1317
}

src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod.php

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,8 @@ class FinalMethod
1010
public function finalMethod()
1111
{
1212
}
13+
14+
public function anotherMethod()
15+
{
16+
}
1317
}

0 commit comments

Comments
 (0)
0