Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,15 @@

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

use Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source\FooBar;

function ($foo)
{
return FooBar::foo($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);
Expand All @@ -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(...);

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

$bar = null;

fn ($foo) => $bar->foo($foo);

function ($foo) use ($bar)
{
return $bar->foo($foo);
};
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

/**
* @method static array test(mixed $value)
*/
class SkipTargetMethodFromMethodDoc
{
public function callTest()
{
$test = array_map(fn($value) => SkipTargetNativeMethodNotExists::test($value), [1, 2, 3, 4]);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Fixture;

class SkipTargetNativeMethodNotExists
{
public function callTest()
{
$test = array_map(fn($value) => SkipTargetNativeMethodNotExists::test($value), [1, 2, 3, 4]);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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(...);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

namespace Rector\Tests\CodingStyle\Rector\FunctionLike\FunctionLikeToFirstClassCallableRector\Source;

class FooBar
{
public static function foo($args)
{
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
use PhpParser\Node\VariadicPlaceholder;
use PhpParser\NodeVisitor;
use PHPStan\Analyser\Scope;
use PHPStan\Reflection\Annotations\AnnotationMethodReflection;
use PHPStan\Reflection\ResolvedFunctionVariantWithOriginal;
use PHPStan\Type\CallableType;
use Rector\NodeTypeResolver\PHPStan\ParametersAcceptorSelectorVariantsWrapper;
Expand Down Expand Up @@ -185,6 +186,18 @@ private function shouldSkip(
return true;
}

$reflection = $this->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;
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍


$functionLike = $this->astResolver->resolveClassMethodOrFunctionFromCall($callLike);
if (! $functionLike instanceof FunctionLike) {
return false;
Expand Down