From 16b71ab97736ee332fd4430a0e62d7e9ef31fcc3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=B4me=20Chilliet?= Date: Thu, 12 Mar 2026 16:34:33 +0100 Subject: [PATCH] feat: Add command in testing application to hunt for static properties MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: Côme Chilliet --- apps/testing/appinfo/info.xml | 5 ++ .../composer/composer/autoload_classmap.php | 1 + .../composer/composer/autoload_static.php | 1 + apps/testing/lib/Command/StaticHunt.php | 73 +++++++++++++++++++ 4 files changed, 80 insertions(+) create mode 100644 apps/testing/lib/Command/StaticHunt.php diff --git a/apps/testing/appinfo/info.xml b/apps/testing/appinfo/info.xml index 12cf4c51e22..cb7d0a31c8e 100644 --- a/apps/testing/appinfo/info.xml +++ b/apps/testing/appinfo/info.xml @@ -16,6 +16,11 @@ + + + OCA\Testing\Command\StaticHunt + + monitoring https://github.com/nextcloud/server/issues diff --git a/apps/testing/composer/composer/autoload_classmap.php b/apps/testing/composer/composer/autoload_classmap.php index ad50a15224a..ee7424a0ea8 100644 --- a/apps/testing/composer/composer/autoload_classmap.php +++ b/apps/testing/composer/composer/autoload_classmap.php @@ -9,6 +9,7 @@ return array( 'Composer\\InstalledVersions' => $vendorDir . '/composer/InstalledVersions.php', 'OCA\\Testing\\AlternativeHomeUserBackend' => $baseDir . '/../lib/AlternativeHomeUserBackend.php', 'OCA\\Testing\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php', + 'OCA\\Testing\\Command\\StaticHunt' => $baseDir . '/../lib/Command/StaticHunt.php', 'OCA\\Testing\\Controller\\ConfigController' => $baseDir . '/../lib/Controller/ConfigController.php', 'OCA\\Testing\\Controller\\LockingController' => $baseDir . '/../lib/Controller/LockingController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => $baseDir . '/../lib/Controller/RateLimitTestController.php', diff --git a/apps/testing/composer/composer/autoload_static.php b/apps/testing/composer/composer/autoload_static.php index d3e37546416..9ea8e6dc0a8 100644 --- a/apps/testing/composer/composer/autoload_static.php +++ b/apps/testing/composer/composer/autoload_static.php @@ -24,6 +24,7 @@ class ComposerStaticInitTesting 'Composer\\InstalledVersions' => __DIR__ . '/..' . '/composer/InstalledVersions.php', 'OCA\\Testing\\AlternativeHomeUserBackend' => __DIR__ . '/..' . '/../lib/AlternativeHomeUserBackend.php', 'OCA\\Testing\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php', + 'OCA\\Testing\\Command\\StaticHunt' => __DIR__ . '/..' . '/../lib/Command/StaticHunt.php', 'OCA\\Testing\\Controller\\ConfigController' => __DIR__ . '/..' . '/../lib/Controller/ConfigController.php', 'OCA\\Testing\\Controller\\LockingController' => __DIR__ . '/..' . '/../lib/Controller/LockingController.php', 'OCA\\Testing\\Controller\\RateLimitTestController' => __DIR__ . '/..' . '/../lib/Controller/RateLimitTestController.php', diff --git a/apps/testing/lib/Command/StaticHunt.php b/apps/testing/lib/Command/StaticHunt.php new file mode 100644 index 00000000000..48fe283f2e3 --- /dev/null +++ b/apps/testing/lib/Command/StaticHunt.php @@ -0,0 +1,73 @@ +setName('testing:static-hunt') + ->setDescription('Hunt for static properties in classes'); + } + + + protected function execute(InputInterface $input, OutputInterface $output): int { + //TODO run on all apps namespaces + $folders = [ + '\\OC' => __DIR__ . '/../../../../lib/private', + '' => __DIR__ . '/../../../../lib/private/legacy', + ]; + foreach ($folders as $namespace => $folder) { + $this->scanFolder($folder, $namespace, $output); + } + + return 0; + } + + private function scanFolder(string $folder, string $namespace, OutputInterface $output): void { + $folder = realpath($folder); + foreach (glob($folder.'/**.php') as $filename) { + try { + $filename = realpath($filename); + $classname = $namespace.substr(str_replace('/', '\\', substr($filename, strlen($folder))), 0, -4); + if (!class_exists($classname)) { + continue; + } + $rClass = new \ReflectionClass($classname); + $staticProperties = $rClass->getStaticProperties(); + if (empty($staticProperties)) { + continue; + } + $output->writeln('# ' . str_replace(\OC::$SERVERROOT, '', $filename) . " $classname"); + foreach ($staticProperties as $property => $value) { + $propertyObject = $rClass->getProperty($property); + $output->write("$propertyObject"); + } + $output->writeln(""); + } catch (\Throwable $t) { + $output->writeln("$t"); + } + } + } +}