diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/fixture.php.inc b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/fixture.php.inc index 826ee48c6b3..90c340f7603 100644 --- a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/fixture.php.inc +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/fixture.php.inc @@ -2,6 +2,8 @@ namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture; +use Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source\FooBar; + function ($foo) { return FooBar::foo($foo); @@ -9,15 +11,6 @@ function ($foo) fn ($foo) => FooBar::foo($foo); -$bar = null; - -fn ($foo) => $bar->foo($foo); - -function ($foo) use ($bar) -{ - return $bar->foo($foo); -}; - function ($foo, $bar, $ray) { return FooBar::foo($foo, $bar); @@ -31,15 +24,11 @@ fn ($foo, $bar, $ray) => FooBar::foo($foo); namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture; -FooBar::foo(...); +use Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source\FooBar; FooBar::foo(...); -$bar = null; - -$bar->foo(...); - -$bar->foo(...); +FooBar::foo(...); FooBar::foo(...); diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_null_variable_call.php.inc b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_null_variable_call.php.inc new file mode 100644 index 00000000000..4a877680162 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_null_variable_call.php.inc @@ -0,0 +1,12 @@ + $bar->foo($foo); + +function ($foo) use ($bar) +{ + return $bar->foo($foo); +}; diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_method_from_method_doc.php.inc b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_method_from_method_doc.php.inc new file mode 100644 index 00000000000..231dd7ab55f --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_method_from_method_doc.php.inc @@ -0,0 +1,14 @@ + SkipTargetNativeMethodNotExists::test($value), [1, 2, 3, 4]); + } +} diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_native_method_not_exists.php.inc b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_native_method_not_exists.php.inc new file mode 100644 index 00000000000..c421d29bb8e --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/skip_target_native_method_not_exists.php.inc @@ -0,0 +1,11 @@ + SkipTargetNativeMethodNotExists::test($value), [1, 2, 3, 4]); + } +} diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/supports_variadic_and_unpack.php.inc b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/supports_variadic_and_unpack.php.inc index 18a91da686b..c947fb5acbc 100644 --- a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/supports_variadic_and_unpack.php.inc +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Fixture/supports_variadic_and_unpack.php.inc @@ -2,6 +2,8 @@ namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture; +use Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source\FooBar; + function (...$foo) { return FooBar::foo(...$foo); @@ -15,6 +17,8 @@ fn (...$foo) => FooBar::foo(...$foo); namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture; +use Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source\FooBar; + FooBar::foo(...); FooBar::foo(...); diff --git a/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Source/FooBar.php b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Source/FooBar.php new file mode 100644 index 00000000000..f181213a615 --- /dev/null +++ b/rules-tests/CodingStyle/Rector/FunctionLike/FunctionLikeToFirstClassCallableRector/Source/FooBar.php @@ -0,0 +1,10 @@ +reflectionResolver->resolveFunctionLikeReflectionFromCall($callLike); + + // not exists, probably by magic method + if ($reflection === null) { + return true; + } + + // exists, but by @method annotation + if ($reflection instanceof AnnotationMethodReflection) { + return true; + } + $functionLike = $this->astResolver->resolveClassMethodOrFunctionFromCall($callLike); if (! $functionLike instanceof FunctionLike) { return false;