Skip to content

Commit 3b7f661

Browse files
committed
Use method_exists for Symfony Console command registration shim.
Replace InstalledVersions version check with method_exists and configure PHPStan to ignore the unavoidable alreadyNarrowedType error on newer Symfony stubs.
1 parent 9e9d961 commit 3b7f661

2 files changed

Lines changed: 7 additions & 22 deletions

File tree

phpstan.neon

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,9 @@ parameters:
66
# Level 9 is the highest level
77
level: 9
88

9-
# ignoreErrors:
10-
# - '#PHPDoc tag @var#'
11-
#
12-
# excludePaths:
13-
# - ./*/*/FileToBeExcluded.php
14-
#
15-
# checkMissingIterableValueType: false
9+
reportUnmatchedIgnoredErrors: false
10+
11+
ignoreErrors:
12+
-
13+
identifier: function.alreadyNarrowedType
14+
path: src/Application.php

src/Application.php

Lines changed: 1 addition & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
use Aws\Exception\CredentialsException;
66
use Bref\Cli\Cli\IO;
77
use Bref\Cli\Cli\Styles;
8-
use Composer\InstalledVersions;
98
use ErrorException;
109
use Exception;
1110
use Symfony\Component\Console\Command\Command;
@@ -39,27 +38,14 @@ public function __construct()
3938
public function safeAddCommand(Command $command): ?Command
4039
{
4140
// addCommand() exists since Symfony Console 7.4; add() was removed in Symfony 8.
42-
$usesAddCommand = self::usesAddCommand();
43-
44-
$method = $usesAddCommand ? 'addCommand' : 'add';
41+
$method = method_exists(parent::class, 'addCommand') ? 'addCommand' : 'add';
4542

4643
/** @var callable(Command): ?Command $register */
4744
$register = [$this, $method];
4845

4946
return $register($command);
5047
}
5148

52-
private static function usesAddCommand(): bool
53-
{
54-
if (! class_exists(InstalledVersions::class) || ! InstalledVersions::isInstalled('symfony/console')) {
55-
throw new Exception('symfony/console is not installed');
56-
}
57-
58-
$version = InstalledVersions::getVersion('symfony/console');
59-
60-
return $version !== null && version_compare($version, '7.4.0', '>=');
61-
}
62-
6349
public function doRun(InputInterface $input, OutputInterface $output): int
6450
{
6551
IO::init($input, $output);

0 commit comments

Comments
 (0)