From 98a06dd7a0fba9df776bce74d974c2f768be5ba4 Mon Sep 17 00:00:00 2001 From: Tobias Weichart Date: Fri, 26 Jul 2019 12:38:08 +0100 Subject: [PATCH 1/3] replace previousHandler content by callable * previous calls to the previousHandler would have resulted in a fatal error * boolean was saved to variable, which later would have been called in custom error_handler * left check for previous existing error_Handler * replaced result with the actually defined and callable error_handler function * replaced empty return statement by null --- .../CacheWarmer/CacheWarmerAggregate.php | 51 +++++++-------- src/Symfony/Component/HttpKernel/Kernel.php | 63 ++++++++++--------- 2 files changed, 58 insertions(+), 56 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php index dd527708bee0f..84e855d649130 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -52,35 +52,36 @@ public function warmUp($cacheDir) { if ($this->debug) { $collectedLogs = []; - $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL'); - $previousHandler = $previousHandler ?: set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { - if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { - return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; - } + $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL') ? + constant('PHPUNIT_COMPOSER_INSTALL') : + set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { + if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { + return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; + } - if (isset($collectedLogs[$message])) { - ++$collectedLogs[$message]['count']; + if (isset($collectedLogs[$message])) { + ++$collectedLogs[$message]['count']; - return; - } + return null; + } - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); - // Clean the trace by removing first frames added by the error handler itself. - for ($i = 0; isset($backtrace[$i]); ++$i) { - if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) { - $backtrace = \array_slice($backtrace, 1 + $i); - break; + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 3); + // Clean the trace by removing first frames added by the error handler itself. + for ($i = 0; isset($backtrace[$i]); ++$i) { + if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) { + $backtrace = \array_slice($backtrace, 1 + $i); + break; + } } - } - $collectedLogs[$message] = [ - 'type' => $type, - 'message' => $message, - 'file' => $file, - 'line' => $line, - 'trace' => $backtrace, - 'count' => 1, - ]; + $collectedLogs[$message] = [ + 'type' => $type, + 'message' => $message, + 'file' => $file, + 'line' => $line, + 'trace' => $backtrace, + 'count' => 1, + ]; }); } @@ -96,7 +97,7 @@ public function warmUp($cacheDir) $warmer->warmUp($cacheDir); } } finally { - if ($this->debug && true !== $previousHandler) { + if ($this->debug && constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { restore_error_handler(); if (file_exists($this->deprecationLogsFilepath)) { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 4f33015653b66..0057af90ef23b 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -505,42 +505,43 @@ protected function initializeContainer() if ($this->debug) { $collectedLogs = []; - $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL'); - $previousHandler = $previousHandler ?: set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { - if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { - return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; - } + $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL') ? + constant('PHPUNIT_COMPOSER_INSTALL') : + set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { + if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { + return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; + } - if (isset($collectedLogs[$message])) { - ++$collectedLogs[$message]['count']; + if (isset($collectedLogs[$message])) { + ++$collectedLogs[$message]['count']; - return; - } + return null; + } - $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5); - // Clean the trace by removing first frames added by the error handler itself. - for ($i = 0; isset($backtrace[$i]); ++$i) { - if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) { - $backtrace = \array_slice($backtrace, 1 + $i); - break; + $backtrace = debug_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 5); + // Clean the trace by removing first frames added by the error handler itself. + for ($i = 0; isset($backtrace[$i]); ++$i) { + if (isset($backtrace[$i]['file'], $backtrace[$i]['line']) && $backtrace[$i]['line'] === $line && $backtrace[$i]['file'] === $file) { + $backtrace = \array_slice($backtrace, 1 + $i); + break; + } } - } - // Remove frames added by DebugClassLoader. - for ($i = \count($backtrace) - 2; 0 < $i; --$i) { - if (DebugClassLoader::class === ($backtrace[$i]['class'] ?? null)) { - $backtrace = [$backtrace[$i + 1]]; - break; + // Remove frames added by DebugClassLoader. + for ($i = \count($backtrace) - 2; 0 < $i; --$i) { + if (DebugClassLoader::class === ($backtrace[$i]['class'] ?? null)) { + $backtrace = [$backtrace[$i + 1]]; + break; + } } - } - $collectedLogs[$message] = [ - 'type' => $type, - 'message' => $message, - 'file' => $file, - 'line' => $line, - 'trace' => [$backtrace[0]], - 'count' => 1, - ]; + $collectedLogs[$message] = [ + 'type' => $type, + 'message' => $message, + 'file' => $file, + 'line' => $line, + 'trace' => [$backtrace[0]], + 'count' => 1, + ]; }); } @@ -549,7 +550,7 @@ protected function initializeContainer() $container = $this->buildContainer(); $container->compile(); } finally { - if ($this->debug && true !== $previousHandler) { + if ($this->debug && constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { restore_error_handler(); file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs))); From 654cdaf3ebb319a309251c50941091597839477f Mon Sep 17 00:00:00 2001 From: Tobias Weichart Date: Fri, 26 Jul 2019 12:47:58 +0100 Subject: [PATCH 2/3] minor spaces fix --- .../Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php | 2 +- src/Symfony/Component/HttpKernel/Kernel.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php index 84e855d649130..550526f1162ae 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -82,7 +82,7 @@ public function warmUp($cacheDir) 'trace' => $backtrace, 'count' => 1, ]; - }); + }); } try { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 0057af90ef23b..39e6c0349000f 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -542,7 +542,7 @@ protected function initializeContainer() 'trace' => [$backtrace[0]], 'count' => 1, ]; - }); + }); } try { From 60d1adf175660318a20bb74233889a933111968c Mon Sep 17 00:00:00 2001 From: Tobias Weichart Date: Fri, 26 Jul 2019 12:50:27 +0100 Subject: [PATCH 3/3] fixed coding standard issue --- .../Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php | 4 ++-- src/Symfony/Component/HttpKernel/Kernel.php | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php index 550526f1162ae..c00e27b7e9c82 100644 --- a/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php +++ b/src/Symfony/Component/HttpKernel/CacheWarmer/CacheWarmerAggregate.php @@ -53,7 +53,7 @@ public function warmUp($cacheDir) if ($this->debug) { $collectedLogs = []; $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL') ? - constant('PHPUNIT_COMPOSER_INSTALL') : + \constant('PHPUNIT_COMPOSER_INSTALL') : set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; @@ -97,7 +97,7 @@ public function warmUp($cacheDir) $warmer->warmUp($cacheDir); } } finally { - if ($this->debug && constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { + if ($this->debug && \constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { restore_error_handler(); if (file_exists($this->deprecationLogsFilepath)) { diff --git a/src/Symfony/Component/HttpKernel/Kernel.php b/src/Symfony/Component/HttpKernel/Kernel.php index 39e6c0349000f..05d5b802a6b75 100644 --- a/src/Symfony/Component/HttpKernel/Kernel.php +++ b/src/Symfony/Component/HttpKernel/Kernel.php @@ -506,7 +506,7 @@ protected function initializeContainer() if ($this->debug) { $collectedLogs = []; $previousHandler = \defined('PHPUNIT_COMPOSER_INSTALL') ? - constant('PHPUNIT_COMPOSER_INSTALL') : + \constant('PHPUNIT_COMPOSER_INSTALL') : set_error_handler(function ($type, $message, $file, $line) use (&$collectedLogs, &$previousHandler) { if (E_USER_DEPRECATED !== $type && E_DEPRECATED !== $type) { return $previousHandler ? $previousHandler($type, $message, $file, $line) : false; @@ -550,7 +550,7 @@ protected function initializeContainer() $container = $this->buildContainer(); $container->compile(); } finally { - if ($this->debug && constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { + if ($this->debug && \constant('PHPUNIT_COMPOSER_INSTALL') !== $previousHandler) { restore_error_handler(); file_put_contents($cacheDir.'/'.$class.'Deprecations.log', serialize(array_values($collectedLogs)));