Skip to content

Commit 0f0352e

Browse files
authored
[10.x] Remove redundant 'setAccessible' methods (#47348)
* refactor: remove redundant 'setAccessible' reflection methods * style: remove blank line
1 parent 81d0221 commit 0f0352e

28 files changed

+9
-73
lines changed

src/Illuminate/Console/Scheduling/ScheduleListCommand.php

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -196,9 +196,7 @@ private function formatCronExpression($expression, $spacing)
196196
*/
197197
private function getClosureLocation(CallbackEvent $event)
198198
{
199-
$callback = tap((new ReflectionClass($event))->getProperty('callback'))
200-
->setAccessible(true)
201-
->getValue($event);
199+
$callback = (new ReflectionClass($event))->getProperty('callback')->getValue($event);
202200

203201
if ($callback instanceof Closure) {
204202
$function = new ReflectionFunction($callback);

src/Illuminate/Console/View/Components/Component.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,6 @@ protected function usingQuestionHelper($callable)
108108
->getParentClass()
109109
->getProperty('questionHelper');
110110

111-
$property->setAccessible(true);
112-
113111
$currentHelper = $property->isInitialized($this->output)
114112
? $property->getValue($this->output)
115113
: new SymfonyQuestionHelper();

src/Illuminate/Database/Eloquent/Builder.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1976,8 +1976,6 @@ protected static function registerMixin($mixin, $replace)
19761976

19771977
foreach ($methods as $method) {
19781978
if ($replace || ! static::hasGlobalMacro($method->name)) {
1979-
$method->setAccessible(true);
1980-
19811979
static::macro($method->name, $method->invoke($mixin));
19821980
}
19831981
}

src/Illuminate/Database/Eloquent/Concerns/HasAttributes.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2227,8 +2227,6 @@ protected static function getAttributeMarkedMutatorMethods($class)
22272227

22282228
if ($returnType instanceof ReflectionNamedType &&
22292229
$returnType->getName() === Attribute::class) {
2230-
$method->setAccessible(true);
2231-
22322230
if (is_callable($method->invoke($instance)->get)) {
22332231
return true;
22342232
}

src/Illuminate/Macroable/Traits/Macroable.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,6 @@ public static function mixin($mixin, $replace = true)
4545

4646
foreach ($methods as $method) {
4747
if ($replace || ! static::hasMacro($method->name)) {
48-
$method->setAccessible(true);
4948
static::macro($method->name, $method->invoke($mixin));
5049
}
5150
}

src/Illuminate/Queue/SerializesModels.php

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -27,8 +27,6 @@ public function __serialize()
2727
continue;
2828
}
2929

30-
$property->setAccessible(true);
31-
3230
if (! $property->isInitialized($this)) {
3331
continue;
3432
}
@@ -82,8 +80,6 @@ public function __unserialize(array $values)
8280
continue;
8381
}
8482

85-
$property->setAccessible(true);
86-
8783
$property->setValue(
8884
$this, $this->getRestoredPropertyValue($values[$name])
8985
);
@@ -98,8 +94,6 @@ public function __unserialize(array $values)
9894
*/
9995
protected function getPropertyValue(ReflectionProperty $property)
10096
{
101-
$property->setAccessible(true);
102-
10397
return $property->getValue($this);
10498
}
10599
}

src/Illuminate/Testing/TestResponse.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1657,8 +1657,6 @@ protected function appendMessageToException($message, $exception)
16571657
{
16581658
$property = new ReflectionProperty($exception, 'message');
16591659

1660-
$property->setAccessible(true);
1661-
16621660
$property->setValue(
16631661
$exception,
16641662
$exception->getMessage().PHP_EOL.PHP_EOL.$message.PHP_EOL

tests/Cookie/CookieTest.php

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,6 @@ public function getCreator()
217217
private function getQueuedPropertyValue(CookieJar $cookieJar)
218218
{
219219
$property = (new ReflectionObject($cookieJar))->getProperty('queued');
220-
$property->setAccessible(true);
221220

222221
return $property->getValue($cookieJar);
223222
}

tests/Database/DatabaseConnectionFactoryTest.php

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -90,9 +90,7 @@ public function testSingleConnectionNotCreatedUntilNeeded()
9090
{
9191
$connection = $this->db->getConnection();
9292
$pdo = new ReflectionProperty(get_class($connection), 'pdo');
93-
$pdo->setAccessible(true);
9493
$readPdo = new ReflectionProperty(get_class($connection), 'readPdo');
95-
$readPdo->setAccessible(true);
9694

9795
$this->assertNotInstanceOf(PDO::class, $pdo->getValue($connection));
9896
$this->assertNotInstanceOf(PDO::class, $readPdo->getValue($connection));
@@ -102,9 +100,7 @@ public function testReadWriteConnectionsNotCreatedUntilNeeded()
102100
{
103101
$connection = $this->db->getConnection('read_write');
104102
$pdo = new ReflectionProperty(get_class($connection), 'pdo');
105-
$pdo->setAccessible(true);
106103
$readPdo = new ReflectionProperty(get_class($connection), 'readPdo');
107-
$readPdo->setAccessible(true);
108104

109105
$this->assertNotInstanceOf(PDO::class, $pdo->getValue($connection));
110106
$this->assertNotInstanceOf(PDO::class, $readPdo->getValue($connection));

tests/Database/DatabaseConnectionTest.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -412,7 +412,6 @@ public function testOnLostConnectionPDOIsSwappedOutsideTransaction()
412412
public function testRunMethodRetriesOnFailure()
413413
{
414414
$method = (new ReflectionClass(Connection::class))->getMethod('run');
415-
$method->setAccessible(true);
416415

417416
$pdo = $this->createMock(DatabaseConnectionTestMockPDO::class);
418417
$mock = $this->getMockConnection(['tryAgainIfCausedByLostConnection'], $pdo);
@@ -429,7 +428,6 @@ public function testRunMethodNeverRetriesIfWithinTransaction()
429428
$this->expectExceptionMessage('(Connection: conn, SQL: ) (Connection: , SQL: )');
430429

431430
$method = (new ReflectionClass(Connection::class))->getMethod('run');
432-
$method->setAccessible(true);
433431

434432
$pdo = $this->getMockBuilder(DatabaseConnectionTestMockPDO::class)->onlyMethods(['beginTransaction'])->getMock();
435433
$mock = $this->getMockConnection(['tryAgainIfCausedByLostConnection'], $pdo);

0 commit comments

Comments
 (0)