-
-
Notifications
You must be signed in to change notification settings - Fork 333
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DeadCode] Skip standalone @return false or true on RemoveUselessRetu…
…rnTagRector (#3202) * [DeadCode] Skip standalone @return false or true on RemoveUselessReturnTagRector * Fixed 🎉 * [ci-review] Rector Rectify * [ci-review] Rector Rectify * Fix phpstan Co-authored-by: GitHub Action <action@github.com>
- Loading branch information
1 parent
40f6d19
commit 0d6234b
Showing
4 changed files
with
110 additions
and
15 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
...veUselessReturnTagRector/Fixture/skip_return_standalone_true_false_by_return_bool.php.inc
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
<?php | ||
|
||
namespace Rector\Tests\DeadCode\Rector\ClassMethod\RemoveUselessReturnTagRector\Fixture; | ||
|
||
/** | ||
* @see https://phpstan.org/r/6fbad07c-4b5e-4d89-8970-03df898abc6e | ||
*/ | ||
final class SkipReturnStandaloneTrueFalseByReturnBool | ||
{ | ||
/** | ||
* @return true | ||
*/ | ||
function someTrue(): bool | ||
{ | ||
return true; | ||
} | ||
|
||
/** | ||
* @return false | ||
*/ | ||
function someFalse(): bool | ||
{ | ||
return false; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
rules/DeadCode/PhpDoc/Guard/StandaloneTypeRemovalGuard.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Rector\DeadCode\PhpDoc\Guard; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Identifier; | ||
use PHPStan\PhpDocParser\Ast\Type\IdentifierTypeNode; | ||
use PHPStan\PhpDocParser\Ast\Type\TypeNode; | ||
|
||
final class StandaloneTypeRemovalGuard | ||
{ | ||
/** | ||
* @var string[] | ||
*/ | ||
private const ALLOWED_TYPES = ['false', 'true']; | ||
|
||
public function isLegal(TypeNode $typeNode, Node $node): bool | ||
{ | ||
if (! $typeNode instanceof IdentifierTypeNode) { | ||
return true; | ||
} | ||
|
||
if (! $node instanceof Identifier) { | ||
return true; | ||
} | ||
|
||
if ($node->toString() !== 'bool') { | ||
return true; | ||
} | ||
|
||
return ! in_array($typeNode->name, self::ALLOWED_TYPES, true); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters