Skip to content

Commit 54f61d2

Browse files
authored
Remove redundant setAccessible methods (#5811)
1 parent a778b60 commit 54f61d2

File tree

5 files changed

+16
-8
lines changed

5 files changed

+16
-8
lines changed

src/Aop/RegisterInjectPropertyHandler.php

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@ public static function register()
3535
if ($annotation instanceof Inject) {
3636
try {
3737
$reflectionProperty = ReflectionManager::reflectProperty($currentClassName, $property);
38-
$reflectionProperty->setAccessible(true);
3938
$container = ApplicationContext::getContainer();
4039
if ($container->has($annotation->value)) {
4140
$reflectionProperty->setValue($object, $container->get($annotation->value));

tests/Annotation/ScannerTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@
3535
* @coversNothing
3636
*/
3737
#[CoversNothing]
38+
/**
39+
* @internal
40+
* @coversNothing
41+
*/
3842
class ScannerTest extends TestCase
3943
{
4044
protected function tearDown(): void
@@ -61,7 +65,6 @@ public function testGetChangedAspects()
6165
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
6266
$ref = new ReflectionClass($scanner);
6367
$property = $ref->getProperty('filesystem');
64-
$property->setAccessible(true);
6568
$property->setValue($scanner, $filesystem = Mockery::mock(Filesystem::class . '[lastModified]'));
6669
$times = [
6770
Debug1Aspect::class => 5,
@@ -73,7 +76,6 @@ public function testGetChangedAspects()
7376
});
7477

7578
$method = $ref->getMethod('getChangedAspects');
76-
$method->setAccessible(true);
7779

7880
$reader = new AnnotationReader();
7981
$scanner->collect($reader, ReflectionManager::reflectClass(Debug2Aspect::class));

tests/AnnotationTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
* @coversNothing
2626
*/
2727
#[CoversNothing]
28+
/**
29+
* @internal
30+
* @coversNothing
31+
*/
2832
class AnnotationTest extends TestCase
2933
{
3034
protected function tearDown(): void
@@ -37,7 +41,6 @@ public function testScanAnnotationsDirectoryNotExist()
3741
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
3842
$ref = new ReflectionClass($scanner);
3943
$method = $ref->getMethod('normalizeDir');
40-
$method->setAccessible(true);
4144

4245
$this->expectException(DirectoryNotExistException::class);
4346
$method->invokeArgs($scanner, [['/not_exists']]);
@@ -48,7 +51,6 @@ public function testScanAnnotationsDirectoryEmpty()
4851
$scanner = new Scanner(new ScanConfig(false, '/'), new NullScanHandler());
4952
$ref = new ReflectionClass($scanner);
5053
$method = $ref->getMethod('normalizeDir');
51-
$method->setAccessible(true);
5254

5355
$this->assertSame([], $method->invokeArgs($scanner, [[]]));
5456
}

tests/Aop/ProxyCallVisitorTest.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,10 @@
2626
* @coversNothing
2727
*/
2828
#[CoversNothing]
29+
/**
30+
* @internal
31+
* @coversNothing
32+
*/
2933
class ProxyCallVisitorTest extends TestCase
3034
{
3135
protected function tearDown(): void
@@ -58,7 +62,6 @@ protected function bar()
5862
$proxyCallVisitor = new ProxyCallVisitor(new VisitorMetadata('SomeClass'));
5963

6064
$reflectionMethod = new ReflectionMethod($proxyCallVisitor, 'shouldRewrite');
61-
$reflectionMethod->setAccessible(true);
6265
$this->assertFalse($reflectionMethod->invoke($proxyCallVisitor, $stmts->stmts[0]));
6366
$this->assertTrue($reflectionMethod->invoke($proxyCallVisitor, $stmts->stmts[1]));
6467
}
@@ -74,7 +77,6 @@ public function testInterfaceShouldNotRewrite()
7477
$proxyCallVisitor = new ProxyCallVisitor($visitorMetadata);
7578

7679
$reflectionMethod = new ReflectionMethod($proxyCallVisitor, 'shouldRewrite');
77-
$reflectionMethod->setAccessible(true);
7880
$this->assertTrue($reflectionMethod->invoke($proxyCallVisitor, new ClassMethod('foo')));
7981

8082
$visitorMetadata->classLike = Node\Stmt\Interface_::class;

tests/ClassLoaderTest.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@
2323
* @coversNothing
2424
*/
2525
#[CoversNothing]
26+
/**
27+
* @internal
28+
* @coversNothing
29+
*/
2630
class ClassLoaderTest extends TestCase
2731
{
2832
public function testDotEnv()
@@ -35,7 +39,6 @@ public function __construct()
3539

3640
$ref = new ReflectionClass($class);
3741
$method = $ref->getMethod('loadDotenv');
38-
$method->setAccessible(true);
3942
$method->invoke($class);
4043

4144
$this->assertNotEquals('0.0.0', env('SW_VERSION'));

0 commit comments

Comments
 (0)