From 38e36478e7d13548c4a2f8485335cf864a0f3cb4 Mon Sep 17 00:00:00 2001 From: Amrouche Hamza Date: Sat, 1 Jun 2019 11:18:04 +0200 Subject: [PATCH] [Monolog] adding the new `$request` argument and remove deprecation --- src/Symfony/Bridge/Monolog/CHANGELOG.md | 5 +++++ src/Symfony/Bridge/Monolog/Logger.php | 20 ++++--------------- .../Monolog/Processor/DebugProcessor.php | 20 ++++--------------- .../Bridge/Monolog/Tests/LoggerTest.php | 20 ++++++------------- .../Tests/Processor/DebugProcessorTest.php | 20 ++++++------------- .../HttpKernel/Log/DebugLoggerInterface.php | 8 ++------ .../EventListener/ExceptionListenerTest.php | 2 +- 7 files changed, 28 insertions(+), 67 deletions(-) diff --git a/src/Symfony/Bridge/Monolog/CHANGELOG.md b/src/Symfony/Bridge/Monolog/CHANGELOG.md index 20f0dc788b..ecc48e9afd 100644 --- a/src/Symfony/Bridge/Monolog/CHANGELOG.md +++ b/src/Symfony/Bridge/Monolog/CHANGELOG.md @@ -1,6 +1,11 @@ CHANGELOG ========= +5.0.0 +----- + + * The methods `DebugProcessor::getLogs()`, `DebugProcessor::countErrors()`, `Logger::getLogs()` and `Logger::countErrors()` have a new `$request` argument. + 4.4.0 ----- diff --git a/src/Symfony/Bridge/Monolog/Logger.php b/src/Symfony/Bridge/Monolog/Logger.php index 5141ac955f..ad9590d029 100644 --- a/src/Symfony/Bridge/Monolog/Logger.php +++ b/src/Symfony/Bridge/Monolog/Logger.php @@ -24,17 +24,11 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface { /** * {@inheritdoc} - * - * @param Request|null $request */ - public function getLogs(/* Request $request = null */) + public function getLogs(Request $request = null) { - if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { - @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); - } - if ($logger = $this->getDebugLogger()) { - return $logger->getLogs(...\func_get_args()); + return $logger->getLogs($request); } return []; @@ -42,17 +36,11 @@ class Logger extends BaseLogger implements DebugLoggerInterface, ResetInterface /** * {@inheritdoc} - * - * @param Request|null $request */ - public function countErrors(/* Request $request = null */) + public function countErrors(Request $request = null) { - if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { - @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); - } - if ($logger = $this->getDebugLogger()) { - return $logger->countErrors(...\func_get_args()); + return $logger->countErrors($request); } return 0; diff --git a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php index 24a670de79..a4594ca012 100644 --- a/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php +++ b/src/Symfony/Bridge/Monolog/Processor/DebugProcessor.php @@ -58,16 +58,10 @@ class DebugProcessor implements DebugLoggerInterface, ResetInterface /** * {@inheritdoc} - * - * @param Request|null $request */ - public function getLogs(/* Request $request = null */) + public function getLogs(Request $request = null) { - if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { - @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); - } - - if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) { + if (null !== $request) { return $this->records[spl_object_hash($request)] ?? []; } @@ -80,16 +74,10 @@ class DebugProcessor implements DebugLoggerInterface, ResetInterface /** * {@inheritdoc} - * - * @param Request|null $request */ - public function countErrors(/* Request $request = null */) + public function countErrors(Request $request = null) { - if (\func_num_args() < 1 && __CLASS__ !== \get_class($this) && __CLASS__ !== (new \ReflectionMethod($this, __FUNCTION__))->getDeclaringClass()->getName() && !$this instanceof \PHPUnit\Framework\MockObject\MockObject && !$this instanceof \Prophecy\Prophecy\ProphecySubjectInterface) { - @trigger_error(sprintf('The "%s()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2.', __METHOD__), E_USER_DEPRECATED); - } - - if (1 <= \func_num_args() && null !== $request = \func_get_arg(0)) { + if (null !== $request) { return $this->errorCount[spl_object_hash($request)] ?? 0; } diff --git a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php index 143200f6c5..5a5ec80f41 100644 --- a/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/LoggerTest.php @@ -125,36 +125,28 @@ class LoggerTest extends TestCase } } - /** - * @group legacy - * @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2. - */ public function testInheritedClassCallGetLogsWithoutArgument() { $loggerChild = new ClassThatInheritLogger('test'); - $loggerChild->getLogs(); + $this->assertNull($loggerChild->getLogs()); } - /** - * @group legacy - * @expectedDeprecation The "Symfony\Bridge\Monolog\Logger::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2. - */ public function testInheritedClassCallCountErrorsWithoutArgument() { $loggerChild = new ClassThatInheritLogger('test'); - $loggerChild->countErrors(); + $this->assertEquals(0, $loggerChild->countErrors()); } } class ClassThatInheritLogger extends Logger { - public function getLogs() + public function getLogs(Request $request = null) { - parent::getLogs(); + parent::getLogs($request); } - public function countErrors() + public function countErrors(Request $request = null) { - parent::countErrors(); + parent::countErrors($request); } } diff --git a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php index 9aceb9337e..388600943b 100644 --- a/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php +++ b/src/Symfony/Bridge/Monolog/Tests/Processor/DebugProcessorTest.php @@ -63,24 +63,16 @@ class DebugProcessorTest extends TestCase $this->assertSame(0, $processor->countErrors(new Request())); } - /** - * @group legacy - * @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::getLogs()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2. - */ public function testInheritedClassCallGetLogsWithoutArgument() { $debugProcessorChild = new ClassThatInheritDebugProcessor(); - $debugProcessorChild->getLogs(); + $this->assertNull($debugProcessorChild->getLogs()); } - /** - * @group legacy - * @expectedDeprecation The "Symfony\Bridge\Monolog\Processor\DebugProcessor::countErrors()" method will have a new "Request $request = null" argument in version 5.0, not defining it is deprecated since Symfony 4.2. - */ public function testInheritedClassCallCountErrorsWithoutArgument() { $debugProcessorChild = new ClassThatInheritDebugProcessor(); - $debugProcessorChild->countErrors(); + $this->assertEquals(0, $debugProcessorChild->countErrors()); } private function getRecord($level = Logger::WARNING, $message = 'test') @@ -99,13 +91,13 @@ class DebugProcessorTest extends TestCase class ClassThatInheritDebugProcessor extends DebugProcessor { - public function getLogs() + public function getLogs(Request $request = null) { - parent::getLogs(); + parent::getLogs($request); } - public function countErrors() + public function countErrors(Request $request = null) { - parent::countErrors(); + parent::countErrors($request); } } diff --git a/src/Symfony/Component/HttpKernel/Log/DebugLoggerInterface.php b/src/Symfony/Component/HttpKernel/Log/DebugLoggerInterface.php index 2a27992e20..2c2eae63ee 100644 --- a/src/Symfony/Component/HttpKernel/Log/DebugLoggerInterface.php +++ b/src/Symfony/Component/HttpKernel/Log/DebugLoggerInterface.php @@ -27,20 +27,16 @@ interface DebugLoggerInterface * timestamp, message, priority, and priorityName. * It can also have an optional context key containing an array. * - * @param Request|null $request The request to get logs for - * * @return array An array of logs */ - public function getLogs(/* Request $request = null */); + public function getLogs(Request $request = null); /** * Returns the number of errors. * - * @param Request|null $request The request to count logs for - * * @return int The number of errors */ - public function countErrors(/* Request $request = null */); + public function countErrors(Request $request = null); /** * Removes all log records. diff --git a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php index 912433e931..c47e61df96 100644 --- a/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php +++ b/src/Symfony/Component/HttpKernel/Tests/EventListener/ExceptionListenerTest.php @@ -178,7 +178,7 @@ class ExceptionListenerTest extends TestCase class TestLogger extends Logger implements DebugLoggerInterface { - public function countErrors() + public function countErrors(Request $request = null) { return \count($this->logs['critical']); }