diff --git a/phpstan/config.neon b/phpstan/config.neon index b13ba7e09..69d7df43d 100644 --- a/phpstan/config.neon +++ b/phpstan/config.neon @@ -13,8 +13,6 @@ parameters: - '../tests/Composer/Test/Autoload/Fixtures/*' - '../tests/Composer/Test/Plugin/Fixtures/*' - '../tests/Composer/Test/PolyfillTestCase.php' - # TODO Remove in 2.3 - - '../src/Composer/Console/HtmlOutputFormatter.php' reportUnmatchedIgnoredErrors: false diff --git a/src/Composer/Command/BaseCommand.php b/src/Composer/Command/BaseCommand.php index 59cbbe9ab..38ddc570f 100644 --- a/src/Composer/Command/BaseCommand.php +++ b/src/Composer/Command/BaseCommand.php @@ -266,13 +266,7 @@ abstract class BaseCommand extends Command $renderer = new Table($output); $renderer->setStyle('compact'); $rendererStyle = $renderer->getStyle(); - if (method_exists($rendererStyle, 'setVerticalBorderChars')) { - $rendererStyle->setVerticalBorderChars(''); - } else { - // TODO remove in composer 2.2 - // @phpstan-ignore-next-line - $rendererStyle->setVerticalBorderChar(''); - } + $rendererStyle->setVerticalBorderChars(''); $rendererStyle->setCellRowContentFormat('%s '); $renderer->setRows($table)->render(); } @@ -282,20 +276,9 @@ abstract class BaseCommand extends Command */ protected function getTerminalWidth() { - if (class_exists('Symfony\Component\Console\Terminal')) { - $terminal = new Terminal(); - $width = $terminal->getWidth(); - } else { - // For versions of Symfony console before 3.2 - // TODO remove in composer 2.2 - // @phpstan-ignore-next-line - list($width) = $this->getApplication()->getTerminalDimensions(); - } - if (null === $width) { - // In case the width is not detected, we're probably running the command - // outside of a real terminal, use space without a limit - $width = PHP_INT_MAX; - } + $terminal = new Terminal(); + $width = $terminal->getWidth(); + if (Platform::isWindows()) { $width--; } else { diff --git a/src/Composer/Command/InitCommand.php b/src/Composer/Command/InitCommand.php index a5cf0fee4..099ec2a2e 100644 --- a/src/Composer/Command/InitCommand.php +++ b/src/Composer/Command/InitCommand.php @@ -731,13 +731,7 @@ EOT $finder = new ExecutableFinder(); $gitBin = $finder->find('git'); - // TODO in v2.3 always call with an array - if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) { - $cmd = new Process(array($gitBin, 'config', '-l')); - } else { - // @phpstan-ignore-next-line - $cmd = new Process(sprintf('%s config -l', ProcessExecutor::escape($gitBin))); - } + $cmd = new Process(array($gitBin, 'config', '-l')); $cmd->run(); if ($cmd->isSuccessful()) { diff --git a/src/Composer/Command/LicensesCommand.php b/src/Composer/Command/LicensesCommand.php index 5375ab08d..3c7c8265e 100644 --- a/src/Composer/Command/LicensesCommand.php +++ b/src/Composer/Command/LicensesCommand.php @@ -85,13 +85,7 @@ EOT $table = new Table($output); $table->setStyle('compact'); $tableStyle = $table->getStyle(); - if (method_exists($tableStyle, 'setVerticalBorderChars')) { - $tableStyle->setVerticalBorderChars(''); - } else { - // TODO remove in composer 2.2 - // @phpstan-ignore-next-line - $tableStyle->setVerticalBorderChar(''); - } + $tableStyle->setVerticalBorderChars(''); $tableStyle->setCellRowContentFormat('%s '); $table->setHeaders(array('Name', 'Version', 'License')); foreach ($packages as $package) { diff --git a/src/Composer/Compiler.php b/src/Composer/Compiler.php index b0aafa74c..ab059312f 100644 --- a/src/Composer/Compiler.php +++ b/src/Composer/Compiler.php @@ -64,13 +64,7 @@ class Compiler $this->versionDate = new \DateTime(trim($process->getOutput())); $this->versionDate->setTimezone(new \DateTimeZone('UTC')); - // TODO in v2.3 always call with an array - if (method_exists('Symfony\Component\Process\Process', 'fromShellCommandline')) { - $process = new Process(array('git', 'describe', '--tags', '--exact-match', 'HEAD'), __DIR__); - } else { - // @phpstan-ignore-next-line - $process = new Process('git describe --tags --exact-match HEAD'); - } + $process = new Process(array('git', 'describe', '--tags', '--exact-match', 'HEAD'), __DIR__); if ($process->run() == 0) { $this->version = trim($process->getOutput()); } else { diff --git a/src/Composer/Console/Application.php b/src/Composer/Console/Application.php index cc9f08685..c40f6b307 100644 --- a/src/Composer/Console/Application.php +++ b/src/Composer/Console/Application.php @@ -440,8 +440,7 @@ class Application extends BaseApplication } catch (\InvalidArgumentException $e) { if ($required) { $this->io->writeError($e->getMessage()); - // TODO composer 2.3 simplify to $this->areExceptionsCaught() - if (!method_exists($this, 'areExceptionsCaught') || $this->areExceptionsCaught()) { + if ($this->areExceptionsCaught()) { exit(1); } throw $e; diff --git a/src/Composer/Console/HtmlOutputFormatter.php b/src/Composer/Console/HtmlOutputFormatter.php index fcb8fab4b..f95933a1b 100644 --- a/src/Composer/Console/HtmlOutputFormatter.php +++ b/src/Composer/Console/HtmlOutputFormatter.php @@ -12,6 +12,7 @@ namespace Composer\Console; +use Closure; use Composer\Pcre\Preg; use Symfony\Component\Console\Formatter\OutputFormatter; use Symfony\Component\Console\Formatter\OutputFormatterStyle; @@ -64,18 +65,19 @@ class HtmlOutputFormatter extends OutputFormatter { $formatted = parent::format($message); + if ($formatted === null) { + return null; + } + $clearEscapeCodes = '(?:39|49|0|22|24|25|27|28)'; - // TODO in 2.3 replace with Closure::fromCallable and then use Preg::replaceCallback - return preg_replace_callback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", array($this, 'formatHtml'), $formatted); + return Preg::replaceCallback("{\033\[([0-9;]+)m(.*?)\033\[(?:".$clearEscapeCodes.";)*?".$clearEscapeCodes."m}s", Closure::fromCallable([$this, 'formatHtml']), $formatted); } /** * @param string[] $matches - * - * @return string */ - private function formatHtml($matches) + private function formatHtml(array $matches): string { $out = '