Skip to content

Commit

Permalink
[TypeDeclaration] Skip void return on AddArrowFunctionReturnTypeRector (
Browse files Browse the repository at this point in the history
  • Loading branch information
samsonasik committed Dec 7, 2022
1 parent b8aff08 commit 99ac002
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\Closure\AddClosureReturnTypeRector\Fixture;

final class SkipVoidReturn
{
public function doNohing(string $a): void
{
echo $a;
}

public function run()
{
fn (string $a) => $this->doNohing($a);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

use PhpParser\Node;
use PhpParser\Node\Expr\ArrowFunction;
use PHPStan\Type\VoidType;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\ValueObject\PhpVersionFeature;
use Rector\PHPStanStaticTypeMapper\Enum\TypeKind;
Expand Down Expand Up @@ -51,6 +52,11 @@ public function refactor(Node $node): ?Node
}

$type = $this->getType($node->expr);

if ($type instanceof VoidType) {
return null;
}

$returnTypeNode = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($type, TypeKind::RETURN);

if ($returnTypeNode === null) {
Expand Down

0 comments on commit 99ac002

Please sign in to comment.