Skip to content

Commit

Permalink
[TypeDeclaration] Handle crash on func call not found on BoolReturnTy…
Browse files Browse the repository at this point in the history
…peFromBooleanStrictReturnsRector (#6327)

* [TypeDeclaration] Handle crash on func call not found on BoolReturnTypeFromBooleanStrictReturnsRector

* Fixed 🎉

* add fixture for found
  • Loading branch information
samsonasik authored Sep 26, 2024
1 parent 398b04d commit e74ecfb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?php

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

class FuncCallFound
{
public function run()
{
return in_array('a', ['a', 'b'], true);
}
}

?>
-----
<?php

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

class FuncCallFound
{
public function run(): bool
{
return in_array('a', ['a', 'b'], true);
}
}

?>
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

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

class SkipFuncCallNotFound
{
public function run()
{
return dt('some');
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,12 @@ private function isNativeBooleanReturnTypeFuncCall(FuncCall $funcCall): bool
return false;
}

$functionReflection = $this->reflectionProvider->getFunction(new Name($functionName), null);
$name = new Name($functionName);
if (! $this->reflectionProvider->hasFunction($name, null)) {
return false;
}

$functionReflection = $this->reflectionProvider->getFunction($name, null);
if (! $functionReflection->isBuiltin()) {
return false;
}
Expand Down

0 comments on commit e74ecfb

Please sign in to comment.