From a6c46a0c2958819397dbfc6c446a74a620ecfcbd Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Sun, 10 Aug 2025 11:30:56 +0200 Subject: [PATCH] Fix PHP8.5 deprecation warnings with ReflectionProperty::setAccessible() --- src/Fixable/Patcher.php | 5 ++++- src/Testing/TestCaseSourceLocatorFactory.php | 4 +++- 2 files changed, 7 insertions(+), 2 deletions(-) diff --git a/src/Fixable/Patcher.php b/src/Fixable/Patcher.php index dcacfec92a..7f126361a4 100644 --- a/src/Fixable/Patcher.php +++ b/src/Fixable/Patcher.php @@ -19,6 +19,7 @@ use function sha1; use function str_starts_with; use function substr; +use const PHP_VERSION_ID; use const PREG_SPLIT_DELIM_CAPTURE; use const PREG_SPLIT_NO_EMPTY; @@ -62,7 +63,9 @@ public function applyDiffs(string $fileName, array $diffs): string $refMerge = new ReflectionClass(PhpMerge::class); $refMergeMethod = $refMerge->getMethod('mergeHunks'); - $refMergeMethod->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $refMergeMethod->setAccessible(true); + } $result = Line::createArray(array_map( static fn ($l) => [$l, Differ::OLD], diff --git a/src/Testing/TestCaseSourceLocatorFactory.php b/src/Testing/TestCaseSourceLocatorFactory.php index a87bf4d9df..9cddb78e99 100644 --- a/src/Testing/TestCaseSourceLocatorFactory.php +++ b/src/Testing/TestCaseSourceLocatorFactory.php @@ -68,7 +68,9 @@ public function create(): SourceLocator ), ]; $vendorDirProperty = $classLoaderReflection->getProperty('vendorDir'); - $vendorDirProperty->setAccessible(true); + if (PHP_VERSION_ID < 80100) { + $vendorDirProperty->setAccessible(true); + } foreach ($classLoaders as $classLoader) { $composerProjectPath = dirname($vendorDirProperty->getValue($classLoader)); if (!is_file($composerProjectPath . '/composer.json')) {