From 03f6f1024d8f1849014ff2ba403c71e2caadee2d Mon Sep 17 00:00:00 2001 From: Gabrieljr42 Date: Thu, 12 Nov 2026 16:16:11 -0300 Subject: [PATCH 1/4] Cast SymfonyOutput::isDecorated() to bool Symfony 5.4 leaves isDecorated() untyped, so the value can be the int 0 or 1 from preg_match. The wrapper return type is bool. --- src/Command/Symfony/SymfonyOutput.php | 2 +- .../Command/Symfony/SymfonyOutputTest.php | 45 +++++++++++++++++++ 2 files changed, 46 insertions(+), 1 deletion(-) create mode 100644 tests/PHPStan/Command/Symfony/SymfonyOutputTest.php diff --git a/src/Command/Symfony/SymfonyOutput.php b/src/Command/Symfony/SymfonyOutput.php index 2d66f11a38f..11255c334ba 100644 --- a/src/Command/Symfony/SymfonyOutput.php +++ b/src/Command/Symfony/SymfonyOutput.php @@ -56,7 +56,7 @@ public function isDebug(): bool public function isDecorated(): bool { - return $this->symfonyOutput->isDecorated(); + return (bool) $this->symfonyOutput->isDecorated(); } } diff --git a/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php new file mode 100644 index 00000000000..59b85d4e87d --- /dev/null +++ b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php @@ -0,0 +1,45 @@ + + */ + public static function dataIsDecorated(): iterable + { + yield 'preg_match hit' => [1, true]; + yield 'preg_match miss' => [0, false]; + yield 'already true' => [true, true]; + yield 'already false' => [false, false]; + } + + #[DataProvider('dataIsDecorated')] + public function testIsDecoratedReturnsBool(mixed $symfonyValue, bool $expected): void + { + $symfonyOutput = new class($symfonyValue) extends NullOutput { + + public function __construct(private mixed $value) + { + } + + public function isDecorated(): mixed + { + return $this->value; + } + + }; + + $output = new SymfonyOutput($symfonyOutput, $this->createStub(OutputStyle::class)); + + self::assertSame($expected, $output->isDecorated()); + } + +} From 02936f067c3ea1343f0a648ec576df03b52d09f6 Mon Sep 17 00:00:00 2001 From: Gabrieljr42 Date: Fri, 13 Nov 2026 15:03:08 -0300 Subject: [PATCH 2/4] Fix mutation testing errors in SymfonyOutput --- src/Command/Symfony/SymfonyOutput.php | 2 +- tests/PHPStan/Command/Symfony/SymfonyOutputTest.php | 1 + 2 files changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Command/Symfony/SymfonyOutput.php b/src/Command/Symfony/SymfonyOutput.php index 11255c334ba..19d94c85fe4 100644 --- a/src/Command/Symfony/SymfonyOutput.php +++ b/src/Command/Symfony/SymfonyOutput.php @@ -56,7 +56,7 @@ public function isDebug(): bool public function isDecorated(): bool { - return (bool) $this->symfonyOutput->isDecorated(); + return (bool) $this->symfonyOutput->isDecorated(); // @phpstan-ignore cast.useless } } diff --git a/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php index 59b85d4e87d..0f0348cc852 100644 --- a/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php +++ b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php @@ -30,6 +30,7 @@ public function __construct(private mixed $value) { } + #[\Override] public function isDecorated(): mixed { return $this->value; From e194559daa04a79fd5f6b562117e53ba0ca3906c Mon Sep 17 00:00:00 2001 From: Gabrieljr42 Date: Fri, 13 Nov 2026 15:23:16 -0300 Subject: [PATCH 3/4] CS: Import Override in SymfonyOutputTest --- tests/PHPStan/Command/Symfony/SymfonyOutputTest.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php index 0f0348cc852..c5392431a62 100644 --- a/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php +++ b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php @@ -2,6 +2,7 @@ namespace PHPStan\Command\Symfony; +use Override; use PHPStan\Command\OutputStyle; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; @@ -30,7 +31,7 @@ public function __construct(private mixed $value) { } - #[\Override] + #[Override] public function isDecorated(): mixed { return $this->value; From ec2a725d4ffd0071e9f380d96dc2bb45968218b3 Mon Sep 17 00:00:00 2001 From: Gabrieljr42 Date: Mon, 16 Nov 2026 14:17:51 -0300 Subject: [PATCH 4/4] Baseline SymfonyOutputTest return type on PHP 7.4 --- build/baseline-pre-8.0.neon | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/build/baseline-pre-8.0.neon b/build/baseline-pre-8.0.neon index 0e94aa40013..f7e784a1f80 100644 --- a/build/baseline-pre-8.0.neon +++ b/build/baseline-pre-8.0.neon @@ -1,5 +1,10 @@ parameters: ignoreErrors: + - + identifier: method.childReturnType + count: 2 + path: ../tests/PHPStan/Command/Symfony/SymfonyOutputTest.php + - message: '#^Call to function method_exists\(\) with ReflectionFunction and ''getClosureCalledCla…'' will always evaluate to false\.$#' identifier: function.impossibleType