Thanks to visit codestin.com
Credit goes to github.com

Skip to content

[Debug] fix detecting overriden final/internal methods implemented using traits #28411

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 9 additions & 11 deletions src/Symfony/Component/Debug/DebugClassLoader.php
Original file line number Diff line number Diff line change
Expand Up @@ -247,25 +247,23 @@ private function checkClass($class, $file = null)
continue;
}

// Method from a trait
if ($method->getFilename() !== $refl->getFileName()) {
continue;
}

if ($isClass && $parent && isset(self::$finalMethods[$parent][$method->name])) {
list($declaringClass, $message) = self::$finalMethods[$parent][$method->name];
@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);
}

foreach ($parentAndTraits as $use) {
if (isset(self::$internalMethods[$use][$method->name])) {
list($declaringClass, $message) = self::$internalMethods[$use][$method->name];
if (\strncmp($ns, $declaringClass, $len)) {
@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);
}
if (isset(self::$internalMethods[$name][$method->name])) {
list($declaringClass, $message) = self::$internalMethods[$name][$method->name];
if (\strncmp($ns, $declaringClass, $len)) {
@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);
}
}

// Method from a trait
if ($method->getFilename() !== $refl->getFileName()) {
continue;
}

// Detect method annotations
if (false === $doc = $method->getDocComment()) {
continue;
Expand Down
15 changes: 6 additions & 9 deletions src/Symfony/Component/Debug/Tests/DebugClassLoaderTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -312,24 +312,21 @@ class_exists('Test\\'.__NAMESPACE__.'\\ExtendsFinalClass', true);

public function testExtendedFinalMethod()
{
set_error_handler(function () { return false; });
$e = error_reporting(0);
trigger_error('', E_USER_NOTICE);
$deprecations = array();
set_error_handler(function ($type, $msg) use (&$deprecations) { $deprecations[] = $msg; });
$e = error_reporting(E_USER_DEPRECATED);

class_exists(__NAMESPACE__.'\\Fixtures\\ExtendedFinalMethod', true);

error_reporting($e);
restore_error_handler();

$lastError = error_get_last();
unset($lastError['file'], $lastError['line']);

$xError = array(
'type' => E_USER_DEPRECATED,
'message' => 'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
'The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".',
);

$this->assertSame($xError, $lastError);
$this->assertSame($xError, $deprecations);
}

public function testExtendedDeprecatedMethodDoesntTriggerAnyNotice()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@

class ExtendedFinalMethod extends FinalMethod
{
use FinalMethod2Trait;

/**
* {@inheritdoc}
*/
Expand Down
7 changes: 7 additions & 0 deletions src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@ public function finalMethod()
{
}

/**
* @final
*/
public function finalMethod2()
{
}

public function anotherMethod()
{
}
Expand Down
10 changes: 10 additions & 0 deletions src/Symfony/Component/Debug/Tests/Fixtures/FinalMethod2Trait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Symfony\Component\Debug\Tests\Fixtures;

trait FinalMethod2Trait
{
public function finalMethod2()
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ class_exists(ExtendedFinalMethod::class);
?>
--EXPECTF--
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod()" method is considered final since version 3.3. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".
The "Symfony\Component\Debug\Tests\Fixtures\FinalMethod::finalMethod2()" method is considered final. It may change without further notice as of its next major version. You should not extend it from "Symfony\Component\Debug\Tests\Fixtures\ExtendedFinalMethod".