-
-
Notifications
You must be signed in to change notification settings - Fork 699
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated Rector to commit 56c250771518c2aa2e17bc64c9986c2dbe9b6fd8
rectorphp/rector-src@56c2507 Decouple AddClosureVoidReturnTypeWhereNoReturnRector to allow leveling by simple node first (#5562)
- Loading branch information
1 parent
de3b3bb
commit d00ebb8
Showing
9 changed files
with
85 additions
and
17 deletions.
There are no files selected for viewing
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
67 changes: 67 additions & 0 deletions
67
rules/TypeDeclaration/Rector/Closure/AddClosureVoidReturnTypeWhereNoReturnRector.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,67 @@ | ||
<?php | ||
|
||
declare (strict_types=1); | ||
namespace Rector\TypeDeclaration\Rector\Closure; | ||
|
||
use PhpParser\Node; | ||
use PhpParser\Node\Expr\Closure; | ||
use PhpParser\Node\Identifier; | ||
use Rector\Rector\AbstractRector; | ||
use Rector\TypeDeclaration\TypeInferer\SilentVoidResolver; | ||
use Rector\ValueObject\PhpVersionFeature; | ||
use Rector\VersionBonding\Contract\MinPhpVersionInterface; | ||
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample; | ||
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition; | ||
/** | ||
* @see \Rector\Tests\TypeDeclaration\Rector\Closure\AddClosureVoidReturnTypeWhereNoReturnRector\AddClosureVoidReturnTypeWhereNoReturnRectorTest | ||
*/ | ||
final class AddClosureVoidReturnTypeWhereNoReturnRector extends AbstractRector implements MinPhpVersionInterface | ||
{ | ||
/** | ||
* @readonly | ||
* @var \Rector\TypeDeclaration\TypeInferer\SilentVoidResolver | ||
*/ | ||
private $silentVoidResolver; | ||
public function __construct(SilentVoidResolver $silentVoidResolver) | ||
{ | ||
$this->silentVoidResolver = $silentVoidResolver; | ||
} | ||
public function getRuleDefinition() : RuleDefinition | ||
{ | ||
return new RuleDefinition('Add closure return type void if there is no return', [new CodeSample(<<<'CODE_SAMPLE' | ||
function () { | ||
} | ||
CODE_SAMPLE | ||
, <<<'CODE_SAMPLE' | ||
function (): void { | ||
} | ||
CODE_SAMPLE | ||
)]); | ||
} | ||
/** | ||
* @return array<class-string<Node>> | ||
*/ | ||
public function getNodeTypes() : array | ||
{ | ||
return [Closure::class]; | ||
} | ||
/** | ||
* @param Closure $node | ||
*/ | ||
public function refactor(Node $node) : ?Node | ||
{ | ||
// already has return type → skip | ||
if ($node->returnType instanceof Node) { | ||
return null; | ||
} | ||
if (!$this->silentVoidResolver->hasExclusiveVoid($node)) { | ||
return null; | ||
} | ||
$node->returnType = new Identifier('void'); | ||
return $node; | ||
} | ||
public function provideMinPhpVersion() : int | ||
{ | ||
return PhpVersionFeature::VOID_TYPE; | ||
} | ||
} |
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
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
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
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
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
Oops, something went wrong.