Skip to content

Commit

Permalink
Remove return type in case of void in RemoveUselessReturnTagRector (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Dec 3, 2023
1 parent b8e6818 commit 026398c
Show file tree
Hide file tree
Showing 6 changed files with 41 additions and 154 deletions.
15 changes: 1 addition & 14 deletions phpstan.neon
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@ parameters:
- "#^Cognitive complexity for \"Rector\\\\Php70\\\\EregToPcreTransformer\\:\\:(.*?)\" is (.*?), keep it under 11$#"
- '#Cognitive complexity for "Rector\\Core\\PhpParser\\Node\\Value\\ValueResolver\:\:getValue\(\)" is \d+, keep it under 11#'
- '#Cognitive complexity for "Rector\\DeadCode\\NodeManipulator\\LivingCodeManipulator\:\:keepLivingCodeFromExpr\(\)" is \d+, keep it under 11#'
- '#Cognitive complexity for "Rector\\DeadCode\\PhpDoc\\DeadReturnTagValueNodeAnalyzer\:\:isDead\(\)" is 13, keep it under 11#'

# is nested expr
-
Expand Down Expand Up @@ -518,23 +519,9 @@ parameters:
- '#Property Rector\\Core\\Contract\\PhpParser\\Node\\StmtsAwareInterface\:\:\$stmts \(array<PhpParser\\Node\\Stmt>\|null\) does not accept array<PhpParser\\Node\\Stmt\|null>#'
- '#Class "Rector\\Utils\\PHPStan\\Rule\\LongAndDependentComplexRectorRule" is missing @see annotation with test case class reference#'

# deprecation
-
message: '#Unreachable statement \- code above always terminates#'
paths:
- rules/TypeDeclaration/Rector/Property/TypedPropertyFromStrictConstructorReadonlyClassRector.php

# deprecated
- '#Class "Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector" is missing @see annotation with test case class reference#'
- '#Register "Rector\\Php71\\Rector\\FuncCall\\CountOnNullRector" service to "php71\.php" config set#'

# dev rule
- '#Class "Rector\\Utils\\Rector\\MoveAbstractRectorToChildrenRector" is missing @see annotation with test case class reference#'

-
path: rules/Transform/Rector/Attribute/AttributeKeyToClassConstFetchRector.php
message: "#Method \"processToClassConstFetch\\(\\)\" returns bool type, so the name should start with is/has/was#"

# deprecated code
- '#Class "Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector" is missing @see annotation with test case class reference#'
- '#Fetching class constant class of deprecated class Rector\\TypeDeclaration\\Rector\\Property\\TypedPropertyFromStrictGetterMethodReturnTypeRector#'
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Fixture;

use stdClass;

class SomethingAndVoid
{
/**
* @return stdClass
*/
function foo(): void
{

}
}

?>
-----
<?php

namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Fixture;

use stdClass;

class SomethingAndVoid
{
function foo(): void
{

}
}

?>
6 changes: 6 additions & 0 deletions rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

namespace Rector\DeadCode\PhpDoc;

use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use PHPStan\Analyser\Scope;
use PHPStan\PhpDocParser\Ast\PhpDoc\ReturnTagValueNode;
Expand Down Expand Up @@ -44,6 +45,11 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod $clas
return false;
}

// in case of void, there is no added value in @return tag
if ($returnType instanceof Identifier && $returnType->toString() === 'void') {
return true;
}

if (! $this->typeComparator->arePhpParserAndPhpStanPhpDocTypesEqual(
$returnType,
$returnTagValueNode->type,
Expand Down
63 changes: 0 additions & 63 deletions rules/Php71/Rector/FuncCall/CountOnNullRector.php

This file was deleted.

This file was deleted.

5 changes: 0 additions & 5 deletions utils/Command/MissingInSetCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,8 @@

use Nette\Utils\Strings;
use Rector\Core\Contract\Rector\ConfigurableRectorInterface;
use Rector\Php71\Rector\FuncCall\CountOnNullRector;
use Rector\Privatization\Rector\Class_\FinalizeClassesWithoutChildrenCollectorRector;
use Rector\TypeDeclaration\Rector\BooleanAnd\BinaryOpNullableToInstanceofRector;
use Rector\TypeDeclaration\Rector\Property\TypedPropertyFromStrictGetterMethodReturnTypeRector;
use Rector\TypeDeclaration\Rector\StmtsAwareInterface\DeclareStrictTypesRector;
use Rector\TypeDeclaration\Rector\While_\WhileNullableToInstanceofRector;
use Rector\Utils\Enum\RectorDirectoryToSetFileMap;
Expand All @@ -33,9 +31,6 @@ final class MissingInSetCommand extends Command
WhileNullableToInstanceofRector::class,
// collectors
FinalizeClassesWithoutChildrenCollectorRector::class,
// deprecated
TypedPropertyFromStrictGetterMethodReturnTypeRector::class,
CountOnNullRector::class,
];

public function __construct(
Expand Down

0 comments on commit 026398c

Please sign in to comment.