Skip to content

Commit 286adc5

Browse files
authored
refactor(reflection): remove deprecated setAccessible usage (#1661)
* refactor(reflection): remove deprecated setAccessible usage refs: #1660 * refactor(reflection): remove deprecated setAccessible usage
1 parent 183a488 commit 286adc5

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

src/ExtractProperties.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ public static function from($target)
1919
{
2020
return collect((new ReflectionClass($target))->getProperties())
2121
->mapWithKeys(function ($property) use ($target) {
22-
$property->setAccessible(true);
22+
if (PHP_VERSION_ID < 80500) {
23+
$property->setAccessible(true);
24+
}
2325

2426
if (PHP_VERSION_ID >= 70400 && ! $property->isInitialized($target)) {
2527
return [];

src/ExtractTags.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,9 @@ protected static function modelsFor(array $targets)
130130
{
131131
return collect($targets)->map(function ($target) {
132132
return collect((new ReflectionClass($target))->getProperties())->map(function ($property) use ($target) {
133-
$property->setAccessible(true);
133+
if (PHP_VERSION_ID < 80500) {
134+
$property->setAccessible(true);
135+
}
134136

135137
if (PHP_VERSION_ID < 70400 || ! is_object($target) || $property->isInitialized($target)) {
136138
return static::resolveValue($property->getValue($target));

tests/Watchers/EventWatcherTest.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,7 +127,10 @@ public function test_format_listeners($listener, $formatted)
127127
Event::listen(DummyEvent::class, $listener);
128128

129129
$method = new \ReflectionMethod(EventWatcher::class, 'formatListeners');
130-
$method->setAccessible(true);
130+
131+
if (PHP_VERSION_ID < 80500) {
132+
$method->setAccessible(true);
133+
}
131134

132135
$this->assertSame($formatted, $method->invoke(new EventWatcher, DummyEvent::class)[0]['name']);
133136
}

0 commit comments

Comments
 (0)