feat: Add command in testing application to hunt for static properties

Signed-off-by: Côme Chilliet <come.chilliet@nextcloud.com>
This commit is contained in:
Côme Chilliet 2026-03-12 16:34:33 +01:00 committed by Carl Schwan
parent f994955dd1
commit 16b71ab977
No known key found for this signature in database
GPG key ID: 02325448204E452A
4 changed files with 80 additions and 0 deletions

View file

@ -16,6 +16,11 @@
<types>
<authentication/>
</types>
<commands>
<command>OCA\Testing\Command\StaticHunt</command>
</commands>
<category>monitoring</category>
<bugs>https://github.com/nextcloud/server/issues</bugs>
<dependencies>

View file

@ -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',

View file

@ -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',

View file

@ -0,0 +1,73 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2026 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\Testing\Command;
use OCA\Theming\ImageManager;
use OCA\Theming\ThemingDefaults;
use OCP\IConfig;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\InputArgument;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
class StaticHunt extends Command {
public function __construct(
private IConfig $config,
) {
parent::__construct();
}
protected function configure() {
$this
->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('<info># ' . str_replace(\OC::$SERVERROOT, '', $filename) . " $classname</info>");
foreach ($staticProperties as $property => $value) {
$propertyObject = $rClass->getProperty($property);
$output->write("$propertyObject");
}
$output->writeln("");
} catch (\Throwable $t) {
$output->writeln("$t");
}
}
}
}