From ed9e9e9f9a16dfce0740b2df138d3e2d070e71bf Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Thu, 22 Jul 2021 12:57:55 +0200 Subject: [PATCH 1/3] Register ErrorHandler early to catch deprecation notices while the Application is being initialized --- bin/composer | 3 +++ src/Composer/Console/Application.php | 2 ++ 2 files changed, 5 insertions(+) diff --git a/bin/composer b/bin/composer index b7ab5318b..b4f18dfdc 100755 --- a/bin/composer +++ b/bin/composer @@ -10,6 +10,7 @@ require __DIR__.'/../src/bootstrap.php'; use Composer\Console\Application; use Composer\XdebugHandler\XdebugHandler; +use Composer\Util\ErrorHandler; error_reporting(-1); @@ -57,6 +58,8 @@ if (function_exists('ini_set')) { putenv('COMPOSER_BINARY='.realpath($_SERVER['argv'][0])); +ErrorHandler::register(); + // run the command application $application = new Application(); $application->run(); diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index bc1cf0993..a6553b277 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -127,6 +127,8 @@ class Application extends BaseApplication $io = $this->io = new ConsoleIO($input, $output, new HelperSet(array( new QuestionHelper(), ))); + + // Register error handler again to pass it the IO instance ErrorHandler::register($io); if ($input->hasParameterOption('--no-cache')) { From ac9f4ac86d1004b1c74ee1943cbaa4f24ad8aa7f Mon Sep 17 00:00:00 2001 From: David Zuelke Date: Thu, 9 Dec 2021 02:30:25 +0100 Subject: [PATCH 2/3] port from main/2.1: ignore all Return type deprecation warnings from Symfony and Composer namespaces (47cf602f9e900a9da65e01a91b3f94a4aacbf7c7, 2be03f0d60a17b2fb05bb88d1754a84bf84641fc) --- src/Composer/Util/ErrorHandler.php | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/src/Composer/Util/ErrorHandler.php b/src/Composer/Util/ErrorHandler.php index c4dabd1d7..a504c4b0a 100644 --- a/src/Composer/Util/ErrorHandler.php +++ b/src/Composer/Util/ErrorHandler.php @@ -52,6 +52,12 @@ class ErrorHandler } if (self::$io) { + // ignore symfony/* deprecation warnings about return types + // also ignore them from the Composer namespace, as 1.x won't get all that fixed anymore + if (preg_match('{^Return type of (Symfony|Composer)\\\\.*ReturnTypeWillChange}is', $message)) { + return true; + } + self::$io->writeError('Deprecation Notice: '.$message.' in '.$file.':'.$line.''); if (self::$io->isVerbose()) { self::$io->writeError('Stack trace:'); From be273491c674567a0f092c4582584066f53d91d8 Mon Sep 17 00:00:00 2001 From: Jordi Boggiano Date: Fri, 3 Sep 2021 21:38:44 +0200 Subject: [PATCH 3/3] Ignore all symfony deprecations --- src/Composer/Util/ErrorHandler.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/Composer/Util/ErrorHandler.php b/src/Composer/Util/ErrorHandler.php index a504c4b0a..9364ce260 100644 --- a/src/Composer/Util/ErrorHandler.php +++ b/src/Composer/Util/ErrorHandler.php @@ -57,6 +57,9 @@ class ErrorHandler if (preg_match('{^Return type of (Symfony|Composer)\\\\.*ReturnTypeWillChange}is', $message)) { return true; } + if (strpos(strtr($file, '\\', '/'), 'vendor/symfony/') !== false) { + return true; + } self::$io->writeError('Deprecation Notice: '.$message.' in '.$file.':'.$line.''); if (self::$io->isVerbose()) {