Skip to content

Commit f41e25c

Browse files
committed
[Php81] Add edge-case fixtures for SimpleScope-resolved RemoveReflectionSetAccessibleCallsRector
Positive (type resolved -> removed): typed param, standalone function, closure. Skip (unresolved/non-matching -> untouched): untyped param (mixed), non-Reflection object, method-call caller (SimpleScope cannot infer return type - safe no-op).
1 parent 8c7e10e commit f41e25c

6 files changed

Lines changed: 127 additions & 0 deletions

File tree

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
use ReflectionProperty;
6+
7+
$accessProperty = function (): void {
8+
$reflectionProperty = new ReflectionProperty('Foo', 'bar');
9+
$reflectionProperty->setAccessible(true);
10+
$reflectionProperty->getValue();
11+
};
12+
13+
?>
14+
-----
15+
<?php
16+
17+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
18+
19+
use ReflectionProperty;
20+
21+
$accessProperty = function (): void {
22+
$reflectionProperty = new ReflectionProperty('Foo', 'bar');
23+
$reflectionProperty->getValue();
24+
};
25+
26+
?>
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
use ReflectionProperty;
6+
7+
final class SkipMethodCallCaller
8+
{
9+
public function run(): void
10+
{
11+
$this->getReflectionProperty()->setAccessible(true);
12+
}
13+
14+
private function getReflectionProperty(): ReflectionProperty
15+
{
16+
return new ReflectionProperty('Foo', 'bar');
17+
}
18+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
final class SkipNonReflectionObject
6+
{
7+
public function run(): void
8+
{
9+
$service = new \stdClass();
10+
$service->setAccessible(true);
11+
}
12+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
final class SkipUntypedParam
6+
{
7+
public function run($reflectionProperty): void
8+
{
9+
$reflectionProperty->setAccessible(true);
10+
}
11+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
use ReflectionMethod;
6+
7+
function standaloneReflectionCall(): void
8+
{
9+
$reflectionMethod = new ReflectionMethod('Foo', 'bar');
10+
$reflectionMethod->setAccessible(true);
11+
$reflectionMethod->invoke(null);
12+
}
13+
14+
?>
15+
-----
16+
<?php
17+
18+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
19+
20+
use ReflectionMethod;
21+
22+
function standaloneReflectionCall(): void
23+
{
24+
$reflectionMethod = new ReflectionMethod('Foo', 'bar');
25+
$reflectionMethod->invoke(null);
26+
}
27+
28+
?>
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
<?php
2+
3+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
4+
5+
use ReflectionProperty;
6+
7+
final class TypedParam
8+
{
9+
public function run(ReflectionProperty $reflectionProperty): void
10+
{
11+
$reflectionProperty->setAccessible(true);
12+
$reflectionProperty->getValue();
13+
}
14+
}
15+
16+
?>
17+
-----
18+
<?php
19+
20+
namespace Rector\Tests\Php81\Rector\MethodCall\RemoveReflectionSetAccessibleCallsRector\Fixture;
21+
22+
use ReflectionProperty;
23+
24+
final class TypedParam
25+
{
26+
public function run(ReflectionProperty $reflectionProperty): void
27+
{
28+
$reflectionProperty->getValue();
29+
}
30+
}
31+
32+
?>

0 commit comments

Comments
 (0)