Skip to content

Commit

Permalink
[TypeDeclaration] Allow add void return type on magic __invoke() meth…
Browse files Browse the repository at this point in the history
…od on AddVoidReturnTypeWhereNoReturnRector (#5376)

* [TypeDeclaration] Allow add void return type on magic __invoke() method on AddVoidReturnTypeWhereNoReturnRector

* implemented
  • Loading branch information
samsonasik committed Dec 22, 2023
1 parent 7ca4de0 commit c2c6558
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
@@ -0,0 +1,27 @@
<?php

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

final class MagicInvoke
{
public function __invoke()
{
echo 'test';
}
}

?>
-----
<?php

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

final class MagicInvoke
{
public function __invoke(): void
{
echo 'test';
}
}

?>
Expand Up @@ -10,6 +10,7 @@
use PhpParser\Node\Stmt\ClassMethod;
use PhpParser\Node\Stmt\Function_;
use PHPStan\Reflection\ClassReflection;
use Rector\Core\NodeAnalyzer\MagicClassMethodAnalyzer;
use Rector\Core\Rector\AbstractRector;
use Rector\Core\Reflection\ReflectionResolver;
use Rector\Core\ValueObject\PhpVersionFeature;
Expand All @@ -27,7 +28,8 @@ final class AddVoidReturnTypeWhereNoReturnRector extends AbstractRector implemen
public function __construct(
private readonly SilentVoidResolver $silentVoidResolver,
private readonly ClassMethodReturnVendorLockResolver $classMethodReturnVendorLockResolver,
private readonly ReflectionResolver $reflectionResolver
private readonly ReflectionResolver $reflectionResolver,
private readonly MagicClassMethodAnalyzer $magicClassMethodAnalyzer
) {
}

Expand Down Expand Up @@ -105,7 +107,7 @@ private function shouldSkipClassMethod(ClassMethod|Function_|Closure $functionLi
return false;
}

if ($functionLike->isMagic()) {
if ($this->magicClassMethodAnalyzer->isUnsafeOverridden($functionLike)) {
return true;
}

Expand Down

0 comments on commit c2c6558

Please sign in to comment.