diff --git a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php index f3c17bf2eec..f7c71a5174b 100644 --- a/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php +++ b/rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php @@ -74,9 +74,8 @@ final class DeadReturnTagValueNodeAnalyzer if ($scope instanceof Scope && $scope->isInTrait() && $returnTagValueNode->type instanceof ThisTypeNode) { return \false; } - // in case of void, there is no added value in @return tag - if ($this->isVoidReturnType($returnType)) { - return !$returnTagValueNode->type instanceof IdentifierTypeNode || (string) $returnTagValueNode->type !== 'never'; + if (!$this->hasUsefullPhpdocType($returnTagValueNode, $returnType)) { + return \true; } if (!$this->typeComparator->arePhpParserAndPhpStanPhpDocTypesEqual($returnType, $returnTagValueNode->type, $classMethod)) { return $this->isDeadNotEqual($returnTagValueNode, $returnType, $classMethod); @@ -99,6 +98,10 @@ final class DeadReturnTagValueNodeAnalyzer { return $node instanceof Identifier && $node->toString() === 'void'; } + private function isNeverReturnType(Node $node) : bool + { + return $node instanceof Identifier && $node->toString() === 'never'; + } private function isDeadNotEqual(ReturnTagValueNode $returnTagValueNode, Node $node, ClassMethod $classMethod) : bool { if ($returnTagValueNode->type instanceof IdentifierTypeNode && (string) $returnTagValueNode->type === 'void') { @@ -122,4 +125,20 @@ final class DeadReturnTagValueNodeAnalyzer } return \false; } + /** + * in case of void,never there is no added value in "@return tag" + * @param mixed $returnType + */ + private function hasUsefullPhpdocType(ReturnTagValueNode $returnTagValueNode, $returnType) : bool + { + if ($this->isVoidReturnType($returnType)) { + if (!$returnTagValueNode->type instanceof IdentifierTypeNode || (string) $returnTagValueNode->type !== 'never') { + return \false; + } + } + if ($this->isNeverReturnType($returnType)) { + return \false; + } + return \true; + } } diff --git a/src/Application/VersionResolver.php b/src/Application/VersionResolver.php index 8930bd90261..aea93fbd486 100644 --- a/src/Application/VersionResolver.php +++ b/src/Application/VersionResolver.php @@ -19,12 +19,12 @@ final class VersionResolver * @api * @var string */ - public const PACKAGE_VERSION = '0.18.12'; + public const PACKAGE_VERSION = '526f4cd09c06842987e46d661b6ad87a8da723a7'; /** * @api * @var string */ - public const RELEASE_DATE = '2023-12-04 12:20:21'; + public const RELEASE_DATE = '2023-12-04 21:48:50'; /** * @var int */