Skip to content

Commit

Permalink
[DeadCode] Skip Remove @return/@param null functionality in case of s…
Browse files Browse the repository at this point in the history
…ub type (#5350)

* [DeadCode] Remove @return/@param null only when has native type already

* move to usefull check

* param null with description

* skip

* [ci-review] Rector Rectify

* skip remove null

* remove null same type

---------

Co-authored-by: GitHub Action <actions@github.com>
  • Loading branch information
samsonasik and actions-user committed Dec 10, 2023
1 parent 287eab3 commit 68c42e7
Show file tree
Hide file tree
Showing 7 changed files with 45 additions and 61 deletions.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
<?php

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

class SkipParamNullWithDescription
{
/**
* @param null $a this is description
*/
public function foo(int $a = null)
{

}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

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

class SkipRemoveNull
{
/**
* @param null $a
*/
public function foo(int $a = null)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ class RemoveNull
/**
* @return null
*/
function foo()
function foo(): null
{
return null;
}
Expand All @@ -21,10 +21,10 @@ namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\

class RemoveNull
{
function foo()
function foo(): null
{
return null;
}
}

?>
?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

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

class SkipRemoveNull
{
/**
* @return null
*/
function foo(): ?int
{
return null;
}
}
14 changes: 0 additions & 14 deletions rules/DeadCode/PhpDoc/DeadParamTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,11 +36,6 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct
return false;
}

// param null is always dead
if ($this->isNullTagValueNode($paramTagValueNode)) {
return true;
}

if ($param->type === null) {
return false;
}
Expand Down Expand Up @@ -75,13 +70,4 @@ public function isDead(ParamTagValueNode $paramTagValueNode, FunctionLike $funct

return ! $this->genericTypeNodeAnalyzer->hasGenericType($paramTagValueNode->type);
}

private function isNullTagValueNode(ParamTagValueNode $paramTagValueNode): bool
{
if (! $paramTagValueNode->type instanceof IdentifierTypeNode) {
return false;
}

return (string) $paramTagValueNode->type === 'null';
}
}
14 changes: 0 additions & 14 deletions rules/DeadCode/PhpDoc/DeadReturnTagValueNodeAnalyzer.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,11 +39,6 @@ public function isDead(ReturnTagValueNode $returnTagValueNode, ClassMethod|Funct
{
$returnType = $functionLike->getReturnType();

if ($this->isNullTagValueNode($returnTagValueNode)) {
// return null is always unused
return true;
}

if ($returnType === null) {
return false;
}
Expand Down Expand Up @@ -156,13 +151,4 @@ private function hasUsefullPhpdocType(ReturnTagValueNode $returnTagValueNode, mi

return ! $this->isNeverReturnType($returnType);
}

private function isNullTagValueNode(ReturnTagValueNode $returnTagValueNode): bool
{
if (! $returnTagValueNode->type instanceof IdentifierTypeNode) {
return false;
}

return (string) $returnTagValueNode->type === 'null';
}
}

0 comments on commit 68c42e7

Please sign in to comment.