From ea4ee65e84ed0a0d899201f3cc1b77c8a44cd13f Mon Sep 17 00:00:00 2001 From: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com> Date: Thu, 19 Mar 2026 19:42:19 +0100 Subject: [PATCH] fix(rector): handle that reflection might not find controllers Signed-off-by: Christoph Wurst <1374172+ChristophWurst@users.noreply.github.com> --- src/Rector/RenameParameterRector.php | 32 ++++++++++++++--- .../test_fixture_app_isolation.php.inc | 35 +++++++++++++++++++ 2 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 tests/Rector/RenameParameterRector/Fixture/test_fixture_app_isolation.php.inc diff --git a/src/Rector/RenameParameterRector.php b/src/Rector/RenameParameterRector.php index d3434f8..c76d564 100644 --- a/src/Rector/RenameParameterRector.php +++ b/src/Rector/RenameParameterRector.php @@ -29,6 +29,7 @@ use function count; use function is_array; +use function str_contains; /** @psalm-suppress PropertyNotSetInConstructor */ class RenameParameterRector extends AbstractRector implements ConfigurableRectorInterface @@ -81,15 +82,36 @@ public function refactor(Node $node): ?Node return null; } + // Get the class name - can be a string or Identifier node + $className = $node->name instanceof Node + ? ($node->name->name ?? '') + : ($node->name ?? ''); + $classReflection = $this->reflectionResolver->resolveClassReflection($node); - if ($classReflection === null) { - return null; + + $shouldProcess = false; + + // If reflection succeeds, verify the class is a Controller or Settings + if ($classReflection !== null) { + $extendsController = $classReflection->is('OCP\AppFramework\Controller'); + $implementsSettingsInterface = $classReflection->implementsInterface('OCP\Settings\ISettings'); + + if ($extendsController || $implementsSettingsInterface) { + $shouldProcess = true; + } } - $extendsController = $classReflection->is('OCP\AppFramework\Controller'); - $implementsSettingsInterface = $classReflection->implementsInterface('OCP\Settings\ISettings'); + // If reflection failed or didn't match, use class name as fallback heuristic + // This allows the rule to work when analyzing apps in isolation where + // Nextcloud core classes aren't available or don't have parent classes declared + if (!$shouldProcess) { + // Only process if class name contains 'Controller' or 'Settings' + if (str_contains($className, 'Controller') || str_contains($className, 'Settings')) { + $shouldProcess = true; + } + } - if (!$extendsController && !$implementsSettingsInterface) { + if (!$shouldProcess) { return null; } diff --git a/tests/Rector/RenameParameterRector/Fixture/test_fixture_app_isolation.php.inc b/tests/Rector/RenameParameterRector/Fixture/test_fixture_app_isolation.php.inc new file mode 100644 index 0000000..0344b38 --- /dev/null +++ b/tests/Rector/RenameParameterRector/Fixture/test_fixture_app_isolation.php.inc @@ -0,0 +1,35 @@ +currentUserId = $UserId; + } +} + +?> +----- +currentUserId = $userId; + } +} + +?>