diff options
author | Thomas Citharel <tcit@tcit.fr> | 2023-03-13 11:05:52 +0100 |
---|---|---|
committer | Côme Chilliet <come.chilliet@nextcloud.com> | 2024-09-10 14:05:59 +0200 |
commit | 82ba7d763bb5fe2fea67df0475ba2516389575ae (patch) | |
tree | 055649271042f801cb6494cd7f96e3201b7ba377 | |
parent | c2150bd0795ba05e1ec94734b12350f544b08ad4 (diff) | |
download | nextcloud-server-82ba7d763bb5fe2fea67df0475ba2516389575ae.tar.gz nextcloud-server-82ba7d763bb5fe2fea67df0475ba2516389575ae.zip |
chore: Code cleanup in lib/private/Console/Application
Signed-off-by: Thomas Citharel <tcit@tcit.fr>
-rw-r--r-- | lib/private/Console/Application.php | 25 |
1 files changed, 15 insertions, 10 deletions
diff --git a/lib/private/Console/Application.php b/lib/private/Console/Application.php index 16ed8894386..22dc8d0c65e 100644 --- a/lib/private/Console/Application.php +++ b/lib/private/Console/Application.php @@ -7,14 +7,18 @@ */ namespace OC\Console; +use ArgumentCountError; use OC\MemoryInfo; use OC\NeedsUpdateException; +use OC\SystemConfig; use OCP\App\AppPathNotFoundException; use OCP\App\IAppManager; use OCP\Console\ConsoleEvent; +use OCP\Defaults; use OCP\EventDispatcher\IEventDispatcher; use OCP\IConfig; use OCP\IRequest; +use OCP\Server; use Psr\Container\ContainerExceptionInterface; use Psr\Log\LoggerInterface; use Symfony\Component\Console\Application as SymfonyApplication; @@ -33,8 +37,8 @@ class Application { private LoggerInterface $logger, private MemoryInfo $memoryInfo, private IAppManager $appManager, + private Defaults $defaults, ) { - $defaults = \OC::$server->get('ThemingDefaults'); $this->application = new SymfonyApplication($defaults->getName(), \OC_Util::getVersionString()); } @@ -44,7 +48,7 @@ class Application { public function loadCommands( InputInterface $input, ConsoleOutputInterface $output - ) { + ): void { // $application is required to be defined in the register_command scripts $application = $this->application; $inputDefinition = $application->getDefinition(); @@ -118,7 +122,7 @@ class Application { $errorOutput = $output->getErrorOutput(); $errorOutput->writeln('Nextcloud is not installed - only a limited number of commands are available'); } - } catch (NeedsUpdateException $e) { + } catch (NeedsUpdateException) { if ($input->getArgument('command') !== '_completion') { $errorOutput = $output->getErrorOutput(); $errorOutput->writeln('Nextcloud or one of the apps require upgrade - only a limited number of commands are available'); @@ -127,7 +131,7 @@ class Application { } if ($input->getFirstArgument() !== 'check') { - $errors = \OC_Util::checkServer(\OC::$server->getSystemConfig()); + $errors = \OC_Util::checkServer(Server::get(SystemConfig::class)); if (!empty($errors)) { foreach ($errors as $error) { $output->writeln((string)$error['error']); @@ -163,13 +167,11 @@ class Application { * * @param bool $boolean Whether to automatically exit after a command execution or not */ - public function setAutoExit($boolean) { + public function setAutoExit(bool $boolean): void { $this->application->setAutoExit($boolean); } /** - * @param InputInterface $input - * @param OutputInterface $output * @return int * @throws \Exception */ @@ -183,15 +185,18 @@ class Application { return $this->application->run($input, $output); } - private function loadCommandsFromInfoXml($commands) { + /** + * @throws \Exception + */ + private function loadCommandsFromInfoXml(iterable $commands): void { foreach ($commands as $command) { try { - $c = \OCP\Server::get($command); + $c = Server::get($command); } catch (ContainerExceptionInterface $e) { if (class_exists($command)) { try { $c = new $command(); - } catch (\ArgumentCountError $e2) { + } catch (ArgumentCountError) { throw new \Exception("Failed to construct console command '$command': " . $e->getMessage(), 0, $e); } } else { |