diff --git a/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector/Fixture/skip_conditional_return_bool.php.inc b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector/Fixture/skip_conditional_return_bool.php.inc new file mode 100644 index 00000000000..d80499f921c --- /dev/null +++ b/rules-tests/DeadCode/Rector/ClassMethod/RemoveUselessReturnTagRector/Fixture/skip_conditional_return_bool.php.inc @@ -0,0 +1,26 @@ + $data + * + * @return ($data is list ? true : false) + */ + private function isListOfArrays(array $data): bool + { + return \array_is_list($data) && \array_all($data, static fn (mixed $item): bool => \is_array($item)); + } + + /** + * @template T of string|int + * @param T $value + * @return (T is string ? true : false) + */ + public function isString(string|int $value): bool + { + return is_string($value); + } +} diff --git a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php index 393c078a92f..04fa30351b9 100644 --- a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php +++ b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php @@ -10,6 +10,8 @@ use PhpParser\Node\Stmt\Function_; use PHPStan\Analyser\Scope; use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode; +use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeForParameterNode; +use PHPStan\PhpDocParser\Ast\Type\ConditionalTypeNode; use PHPStan\PhpDocParser\Ast\Type\GenericTypeNode; use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; use PHPStan\PhpDocParser\Ast\Type\ThisTypeNode; @@ -54,6 +56,10 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod|Funct return false; } + if ($returnTagValueNode->type instanceof ConditionalTypeNode || $returnTagValueNode->type instanceof ConditionalTypeForParameterNode) { + return false; + } + $docType = $this->staticTypeMapper->mapPHPStanPhpDocTypeNodeToPHPStanType( $returnTagValueNode->type, $functionLike