Updated Rector to commit 526f4cd09c06842987e46d661b6ad87a8da723a7

526f4cd09c Remove return type in case of never in RemoveUselessReturnTagRector (#5323)
This commit is contained in:
Tomas Votruba 2023-12-04 14:51:16 +00:00
parent ed8d5352a3
commit 1754c2c66a
2 changed files with 24 additions and 5 deletions

View File

@ -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;
}
}

View File

@ -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
*/