Skip to content

Commit

Permalink
add docblock @return null
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 11, 2023
1 parent 8733068 commit 5c098e3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ namespace Rector\Tests\DowngradePhp82\Rector\Class_\DowngradeStandaloneNullTrueF

final class ReturnNull
{
/**
* @return null
*/
public function run(): mixed
{
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,9 @@
use PhpParser\Node\FunctionLike;
use PhpParser\Node\Identifier;
use PhpParser\Node\Stmt\ClassMethod;
use Rector\BetterPhpDocParser\PhpDocInfo\PhpDocInfoFactory;
use Rector\BetterPhpDocParser\PhpDocManipulator\PhpDocTypeChanger;
use Rector\Comments\NodeDocBlock\DocBlockUpdater;
use Rector\Core\Rector\AbstractRector;
use Symplify\RuleDocGenerator\ValueObject\CodeSample\CodeSample;
use Symplify\RuleDocGenerator\ValueObject\RuleDefinition;
Expand All @@ -19,6 +22,14 @@
*/
final class DowngradeStandaloneNullTrueFalseReturnTypeRector extends AbstractRector
{
public function __construct(
private readonly PhpDocInfoFactory $phpDocInfoFactory,
private readonly PhpDocTypeChanger $phpDocTypeChanger,
private readonly DocBlockUpdater $docBlockUpdater
)
{
}

/**
* @return array<class-string<Node>>
*/
Expand Down Expand Up @@ -79,6 +90,10 @@ public function refactor(Node $node): ?Node

// todo: verify parent
$node->returnType = new Identifier('mixed');
return null;

$phpDocInfo = $this->phpDocInfoFactory->createFromNodeOrEmpty($node);
$this->phpDocTypeChanger->changeReturnType($node, $phpDocInfo, new \PHPStan\Type\NullType());

return $node;
}
}

0 comments on commit 5c098e3

Please sign in to comment.