Skip to content

Commit 4ed3b10

Browse files
committed
chore: ran rector in preparation for downgrade testing
1 parent 5b59464 commit 4ed3b10

4 files changed

Lines changed: 50 additions & 45 deletions

File tree

rules-tests/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector/RemoveReflectionSetAccessibleCallsRectorTest.php

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector;
66

7+
use Iterator;
78
use PHPUnit\Framework\Attributes\DataProvider;
89
use Rector\Testing\PHPUnit\AbstractRectorTestCase;
910

@@ -16,9 +17,9 @@ public function testRule(string $filePath): void
1617
}
1718

1819
/**
19-
* @return \Iterator<array<string>>
20+
* @return Iterator<array<string>>
2021
*/
21-
public static function provideData(): \Iterator
22+
public static function provideData(): Iterator
2223
{
2324
return self::yieldFilesFromDirectory(__DIR__ . '/Fixture');
2425
}

rules/CodingStyle/Rector/FuncCall/ClosureFromCallableToFirstClassCallableRector.php

Lines changed: 44 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,19 @@
44

55
namespace Rector\CodingStyle\Rector\FuncCall;
66

7+
use PhpParser\Node\Expr\StaticCall;
8+
use PhpParser\Node\Arg;
9+
use PhpParser\Node\Scalar\String_;
10+
use PhpParser\Node\Expr\FuncCall;
11+
use PhpParser\Node\VariadicPlaceholder;
12+
use PhpParser\Node\Expr\Array_;
13+
use PhpParser\Node\Expr\Variable;
14+
use PhpParser\Node\Expr\MethodCall;
15+
use PhpParser\Node\Name\FullyQualified;
16+
use PhpParser\Node\Expr\ClassConstFetch;
17+
use PhpParser\Node\Expr;
18+
use PhpParser\Node\Name;
19+
use PhpParser\Node\Identifier;
720
use PhpParser\Node;
821
use Rector\Rector\AbstractRector;
922
use Rector\ValueObject\PhpVersionFeature;
@@ -26,9 +39,9 @@ public function getRuleDefinition(): RuleDefinition
2639
'Change `Closure::fromCallable()` to first class callable syntax',
2740
[
2841
new CodeSample('Closure::fromCallable([$obj, \'method\']);', '$obj->method(...);'),
29-
new CodeSample('Closure::fromCallable(\'trim\');', 'trim(...);'),
42+
new CodeSample("Closure::fromCallable('trim');", 'trim(...);'),
3043
new CodeSample(
31-
'Closure::fromCallable([\'SomeClass\', \'staticMethod\']);',
44+
"Closure::fromCallable(['SomeClass', 'staticMethod']);",
3245
'SomeClass::staticMethod(...);'
3346
),
3447
]
@@ -41,11 +54,11 @@ public function getRuleDefinition(): RuleDefinition
4154
*/
4255
public function getNodeTypes(): array
4356
{
44-
return [Node\Expr\StaticCall::class];
57+
return [StaticCall::class];
4558
}
4659

4760
/**
48-
* @param Node\Expr\StaticCall $node
61+
* @param StaticCall $node
4962
*/
5063
public function refactor(Node $node): ?Node
5164
{
@@ -54,52 +67,52 @@ public function refactor(Node $node): ?Node
5467
}
5568

5669
$arg = $node->args[0];
57-
if (! $arg instanceof Node\Arg) {
70+
if (! $arg instanceof Arg) {
5871
return null;
5972
}
6073

61-
if ($arg->value instanceof Node\Scalar\String_) {
62-
return new Node\Expr\FuncCall(
74+
if ($arg->value instanceof String_) {
75+
return new FuncCall(
6376
$this->toFullyQualified($arg->value->value),
64-
[new Node\VariadicPlaceholder()],
77+
[new VariadicPlaceholder()],
6578
);
6679
}
6780

68-
if ($arg->value instanceof Node\Expr\Array_) {
81+
if ($arg->value instanceof Array_) {
6982
if (
7083
! array_key_exists(0, $arg->value->items)
7184
|| ! array_key_exists(1, $arg->value->items)
72-
|| ! $arg->value->items[1]->value instanceof Node\Scalar\String_
85+
|| ! $arg->value->items[1]->value instanceof String_
7386
) {
7487
return null;
7588
}
7689

77-
if ($arg->value->items[0]->value instanceof Node\Expr\Variable) {
78-
return new Node\Expr\MethodCall(
90+
if ($arg->value->items[0]->value instanceof Variable) {
91+
return new MethodCall(
7992
$arg->value->items[0]->value,
8093
$arg->value->items[1]->value->value,
81-
[new Node\VariadicPlaceholder()],
94+
[new VariadicPlaceholder()],
8295
);
8396
}
8497

85-
if ($arg->value->items[0]->value instanceof Node\Scalar\String_) {
86-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->value);
87-
} elseif ($arg->value->items[0]->value instanceof Node\Expr\ClassConstFetch) {
88-
if ($arg->value->items[0]->value->class instanceof Node\Expr) {
98+
if ($arg->value->items[0]->value instanceof String_) {
99+
$classNode = new FullyQualified($arg->value->items[0]->value->value);
100+
} elseif ($arg->value->items[0]->value instanceof ClassConstFetch) {
101+
if ($arg->value->items[0]->value->class instanceof Expr) {
89102
return null;
90103
}
91104

92-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->class->name);
93-
} elseif ($arg->value->items[0]->value instanceof Node\Name\FullyQualified) {
94-
$classNode = new Node\Name\FullyQualified($arg->value->items[0]->value->name);
105+
$classNode = new FullyQualified($arg->value->items[0]->value->class->name);
106+
} elseif ($arg->value->items[0]->value instanceof FullyQualified) {
107+
$classNode = new FullyQualified($arg->value->items[0]->value->name);
95108
} else {
96109
return null;
97110
}
98111

99-
return new Node\Expr\StaticCall(
112+
return new StaticCall(
100113
$classNode,
101114
$arg->value->items[1]->value->value,
102-
[new Node\VariadicPlaceholder()],
115+
[new VariadicPlaceholder()],
103116
);
104117
}
105118

@@ -111,37 +124,33 @@ public function provideMinPhpVersion(): int
111124
return PhpVersionFeature::FIRST_CLASS_CALLABLE_SYNTAX;
112125
}
113126

114-
public function shouldSkip(Node\Expr\StaticCall $node): bool
127+
public function shouldSkip(StaticCall $staticCall): bool
115128
{
116-
if (! $node->class instanceof Node\Name) {
129+
if (! $staticCall->class instanceof Name) {
117130
return true;
118131
}
119132

120-
if (! $this->isName($node->class, 'Closure')) {
133+
if (! $this->isName($staticCall->class, 'Closure')) {
121134
return true;
122135
}
123136

124-
if (! $node->name instanceof Node\Identifier || $node->name->name !== 'fromCallable') {
137+
if (! $staticCall->name instanceof Identifier || $staticCall->name->name !== 'fromCallable') {
125138
return true;
126139
}
127140

128-
if ($node->isFirstClassCallable()) {
141+
if ($staticCall->isFirstClassCallable()) {
129142
return true;
130143
}
131144

132-
$args = $node->getArgs();
133-
if (count($args) !== 1) {
134-
return true;
135-
}
136-
137-
return false;
145+
$args = $staticCall->getArgs();
146+
return count($args) !== 1;
138147
}
139148

140-
public function toFullyQualified(string $functionName): Node\Name\FullyQualified
149+
public function toFullyQualified(string $functionName): FullyQualified
141150
{
142151
// in case there's already a \ prefix, remove it
143152
$functionName = ltrim($functionName, '\\');
144153

145-
return new Node\Name\FullyQualified($functionName);
154+
return new FullyQualified($functionName);
146155
}
147156
}

rules/Php81/Rector/MethodCall/RemoveReflectionSetAccessibleCallsRector.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ public function refactor(Node $node): ?int
4747
return null;
4848
}
4949

50-
if ($this->isObjectType($methodCall->var, new ObjectType('ReflectionProperty')) === true
51-
|| $this->isObjectType($methodCall->var, new ObjectType('ReflectionMethod')) === true
50+
if ($this->isObjectType($methodCall->var, new ObjectType('ReflectionProperty'))
51+
|| $this->isObjectType($methodCall->var, new ObjectType('ReflectionMethod'))
5252
) {
5353
return NodeVisitor::REMOVE_NODE;
5454
}

src/Util/Reflection/PrivatesAccessor.php

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -47,25 +47,20 @@ public function callPrivateMethod(object|string $object, string $methodName, arr
4747
public function getPrivateProperty(object $object, string $propertyName): mixed
4848
{
4949
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
50-
$reflectionProperty->setAccessible(true);
5150

5251
return $reflectionProperty->getValue($object);
5352
}
5453

5554
public function setPrivateProperty(object $object, string $propertyName, mixed $value): void
5655
{
5756
$reflectionProperty = $this->resolvePropertyReflection($object, $propertyName);
58-
$reflectionProperty->setAccessible(true);
5957

6058
$reflectionProperty->setValue($object, $value);
6159
}
6260

6361
private function createAccessibleMethodReflection(object $object, string $methodName): ReflectionMethod
6462
{
65-
$reflectionMethod = new ReflectionMethod($object, $methodName);
66-
$reflectionMethod->setAccessible(true);
67-
68-
return $reflectionMethod;
63+
return new ReflectionMethod($object, $methodName);
6964
}
7065

7166
private function resolvePropertyReflection(object $object, string $propertyName): ReflectionProperty

0 commit comments

Comments
 (0)