Skip to content

Commit 0021d18

Browse files
committed
Updated Rector to commit fe319d74bc9242099c980b8665e50976825edb73
rectorphp/rector-src@fe319d7 Rectify (#7084)
1 parent 509b187 commit 0021d18

2 files changed

Lines changed: 42 additions & 35 deletions

File tree

rules/CodingStyle/Rector/FuncCall/ClosureFromCallableToFirstClassCallableRector.php

Lines changed: 40 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44
namespace Rector\CodingStyle\Rector\FuncCall;
55

66
use PhpParser\Node;
7+
use PhpParser\Node\Arg;
8+
use PhpParser\Node\Expr;
9+
use PhpParser\Node\Expr\Array_;
10+
use PhpParser\Node\Expr\ClassConstFetch;
11+
use PhpParser\Node\Expr\FuncCall;
12+
use PhpParser\Node\Expr\MethodCall;
13+
use PhpParser\Node\Expr\StaticCall;
14+
use PhpParser\Node\Expr\Variable;
15+
use PhpParser\Node\Identifier;
16+
use PhpParser\Node\Name;
17+
use PhpParser\Node\Name\FullyQualified;
18+
use PhpParser\Node\Scalar\String_;
19+
use PhpParser\Node\VariadicPlaceholder;
720
use Rector\Rector\AbstractRector;
821
use Rector\ValueObject\PhpVersionFeature;
922
use Rector\VersionBonding\Contract\MinPhpVersionInterface;
@@ -14,86 +27,80 @@
1427
*/
1528
final class ClosureFromCallableToFirstClassCallableRector extends AbstractRector implements MinPhpVersionInterface
1629
{
17-
public function __construct()
18-
{
19-
}
2030
public function getRuleDefinition() : RuleDefinition
2131
{
22-
return new RuleDefinition('Change `Closure::fromCallable()` to first class callable syntax', [new CodeSample('Closure::fromCallable([$obj, \'method\']);', '$obj->method(...);'), new CodeSample('Closure::fromCallable(\'trim\');', 'trim(...);'), new CodeSample('Closure::fromCallable([\'SomeClass\', \'staticMethod\']);', 'SomeClass::staticMethod(...);')]);
32+
return new RuleDefinition('Change `Closure::fromCallable()` to first class callable syntax', [new CodeSample('Closure::fromCallable([$obj, \'method\']);', '$obj->method(...);'), new CodeSample("Closure::fromCallable('trim');", 'trim(...);'), new CodeSample("Closure::fromCallable(['SomeClass', 'staticMethod']);", 'SomeClass::staticMethod(...);')]);
2333
}
2434
/**
2535
* @return array<class-string<Node>>
2636
*/
2737
public function getNodeTypes() : array
2838
{
29-
return [Node\Expr\StaticCall::class];
39+
return [StaticCall::class];
3040
}
3141
/**
32-
* @param Node\Expr\StaticCall $node
42+
* @param StaticCall $node
3343
*/
3444
public function refactor(Node $node) : ?Node
3545
{
3646
if ($this->shouldSkip($node)) {
3747
return null;
3848
}
3949
$arg = $node->args[0];
40-
if (!$arg instanceof Node\Arg) {
50+
if (!$arg instanceof Arg) {
4151
return null;
4252
}
43-
if ($arg->value instanceof Node\Scalar\String_) {
44-
return new Node\Expr\FuncCall($this->toFullyQualified($arg->value->value), [new Node\VariadicPlaceholder()]);
53+
if ($arg->value instanceof String_) {
54+
return new FuncCall($this->toFullyQualified($arg->value->value), [new VariadicPlaceholder()]);
4555
}
46-
if ($arg->value instanceof Node\Expr\Array_) {
47-
if (!\array_key_exists(0, $arg->value->items) || !\array_key_exists(1, $arg->value->items) || !$arg->value->items[1]->value instanceof Node\Scalar\String_) {
56+
if ($arg->value instanceof Array_) {
57+
if (!\array_key_exists(0, $arg->value->items) || !\array_key_exists(1, $arg->value->items) || !$arg->value->items[1]->value instanceof String_) {
4858
return null;
4959
}
50-
if ($arg->value->items[0]->value instanceof Node\Expr\Variable) {
51-
return new Node\Expr\MethodCall($arg->value->items[0]->value, $arg->value->items[1]->value->value, [new Node\VariadicPlaceholder()]);
60+
if ($arg->value->items[0]->value instanceof Variable) {
61+
return new MethodCall($arg->value->items[0]->value, $arg->value->items[1]->value->value, [new VariadicPlaceholder()]);
5262
}
53-
if ($arg->value->items[0]->value instanceof Node\Scalar\String_) {
54-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->value);
55-
} elseif ($arg->value->items[0]->value instanceof Node\Expr\ClassConstFetch) {
56-
if ($arg->value->items[0]->value->class instanceof Node\Expr) {
63+
if ($arg->value->items[0]->value instanceof String_) {
64+
$classNode = new FullyQualified($arg->value->items[0]->value->value);
65+
} elseif ($arg->value->items[0]->value instanceof ClassConstFetch) {
66+
if ($arg->value->items[0]->value->class instanceof Expr) {
5767
return null;
5868
}
59-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->class->name);
60-
} elseif ($arg->value->items[0]->value instanceof Node\Name\FullyQualified) {
61-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->name);
69+
$classNode = new FullyQualified($arg->value->items[0]->value->class->name);
70+
} elseif ($arg->value->items[0]->value instanceof FullyQualified) {
71+
$classNode = new FullyQualified($arg->value->items[0]->value->name);
6272
} else {
6373
return null;
6474
}
65-
return new Node\Expr\StaticCall($classNode, $arg->value->items[1]->value->value, [new Node\VariadicPlaceholder()]);
75+
return new StaticCall($classNode, $arg->value->items[1]->value->value, [new VariadicPlaceholder()]);
6676
}
6777
return $node;
6878
}
6979
public function provideMinPhpVersion() : int
7080
{
7181
return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX;
7282
}
73-
public function shouldSkip(Node\Expr\StaticCall $node) : bool
83+
public function shouldSkip(StaticCall $staticCall) : bool
7484
{
75-
if (!$node->class instanceof Node\Name) {
76-
return \true;
77-
}
78-
if (!$this->isName($node->class, 'Closure')) {
85+
if (!$staticCall->class instanceof Name) {
7986
return \true;
8087
}
81-
if (!$node->name instanceof Node\Identifier || $node->name->name !== 'fromCallable') {
88+
if (!$this->isName($staticCall->class, 'Closure')) {
8289
return \true;
8390
}
84-
if ($node->isFirstClassCallable()) {
91+
if (!$staticCall->name instanceof Identifier || $staticCall->name->name !== 'fromCallable') {
8592
return \true;
8693
}
87-
$args = $node->getArgs();
88-
if (\count($args) !== 1) {
94+
if ($staticCall->isFirstClassCallable()) {
8995
return \true;
9096
}
91-
return \false;
97+
$args = $staticCall->getArgs();
98+
return \count($args) !== 1;
9299
}
93-
public function toFullyQualified(string $functionName) : Node\Name\FullyQualified
100+
public function toFullyQualified(string $functionName) : FullyQualified
94101
{
95102
// in case there's already a \ prefix, remove it
96103
$functionName = \ltrim($functionName, '\\');
97-
return new Node\Name\FullyQualified($functionName);
104+
return new FullyQualified($functionName);
98105
}
99106
}

src/Application/VersionResolver.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,12 +19,12 @@ final class VersionResolver
1919
* @api
2020
* @var string
2121
*/
22-
public const PACKAGE_VERSION = 'eb07bffc89331e6fa6df521eeb48c5b27e1df531';
22+
public const PACKAGE_VERSION = 'fe319d74bc9242099c980b8665e50976825edb73';
2323
/**
2424
* @api
2525
* @var string
2626
*/
27-
public const RELEASE_DATE = '2025-07-22 22:00:50';
27+
public const RELEASE_DATE = '2025-07-23 07:06:07';
2828
/**
2929
* @var int
3030
*/

0 commit comments

Comments
 (0)