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 diff --git a/src/Command/Symfony/SymfonyOutput.php b/src/Command/Symfony/SymfonyOutput.php index 2d66f11a38f..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 $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 new file mode 100644 index 00000000000..c5392431a62 --- /dev/null +++ b/tests/PHPStan/Command/Symfony/SymfonyOutputTest.php @@ -0,0 +1,47 @@ + + */ + 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) + { + } + + #[Override] + public function isDecorated(): mixed + { + return $this->value; + } + + }; + + $output = new SymfonyOutput($symfonyOutput, $this->createStub(OutputStyle::class)); + + self::assertSame($expected, $output->isDecorated()); + } + +}