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"); } } } }