Skip to content

Commit

Permalink
[TypeDeclaration] Skip void type for arrow funtcions (#649)
Browse files Browse the repository at this point in the history
  • Loading branch information
TomasVotruba committed Aug 11, 2021
1 parent c8a4625 commit 5b98e93
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Fixture;

use Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source\CallWithVoid;

final class SkipArrowFunctionVoid
{
public function run(CallWithVoid $callWithVoid)
{
fn() => $callWithVoid->nothing();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

declare(strict_types=1);

namespace Rector\Tests\TypeDeclaration\Rector\ClassMethod\ReturnTypeFromStrictTypedCallRector\Source;

final class CallWithVoid
{
public function nothing(): void
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -143,6 +143,12 @@ public function refactor(Node $node): ?Node
private function processArrowFunction(ArrowFunction $arrowFunction): ?ArrowFunction
{
$resolvedType = $this->nodeTypeResolver->resolve($arrowFunction->expr);

// void type is not accepted for arrow functions - https://www.php.net/manual/en/functions.arrow.php#125673
if ($resolvedType instanceof VoidType) {
return null;
}

$returnType = $this->staticTypeMapper->mapPHPStanTypeToPhpParserNode($resolvedType, TypeKind::RETURN());

if (! $returnType instanceof Node) {
Expand Down

0 comments on commit 5b98e93

Please sign in to comment.