Skip to content

Commit a9d81cf

Browse files
committed
Fix PHP8.5 deprecation warnings with ReflectionProperty::setAccessible()
1 parent 745ae5a commit a9d81cf

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

src/Fixable/Patcher.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,8 @@
1919
use function sha1;
2020
use function str_starts_with;
2121
use function substr;
22+
use function version_compare;
23+
use const PHP_VERSION;
2224
use const PREG_SPLIT_DELIM_CAPTURE;
2325
use const PREG_SPLIT_NO_EMPTY;
2426

@@ -62,7 +64,9 @@ public function applyDiffs(string $fileName, array $diffs): string
6264

6365
$refMerge = new ReflectionClass(PhpMerge::class);
6466
$refMergeMethod = $refMerge->getMethod('mergeHunks');
65-
$refMergeMethod->setAccessible(true);
67+
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
68+
$refMergeMethod->setAccessible(true);
69+
}
6670

6771
$result = Line::createArray(array_map(
6872
static fn ($l) => [$l, Differ::OLD],

src/Testing/TestCaseSourceLocatorFactory.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@
2323
use function is_file;
2424
use function serialize;
2525
use function sha1;
26+
use function version_compare;
27+
use const PHP_VERSION;
2628
use const PHP_VERSION_ID;
2729

2830
final class TestCaseSourceLocatorFactory
@@ -68,7 +70,9 @@ public function create(): SourceLocator
6870
),
6971
];
7072
$vendorDirProperty = $classLoaderReflection->getProperty('vendorDir');
71-
$vendorDirProperty->setAccessible(true);
73+
if (version_compare(PHP_VERSION, '8.1.0', '<')) {
74+
$vendorDirProperty->setAccessible(true);
75+
}
7276
foreach ($classLoaders as $classLoader) {
7377
$composerProjectPath = dirname($vendorDirProperty->getValue($classLoader));
7478
if (!is_file($composerProjectPath . '/composer.json')) {

0 commit comments

Comments
 (0)