chore: Code cleanup in lib/private/Console/Application

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
This commit is contained in:
Thomas Citharel 2023-03-13 11:05:52 +01:00 committed by Côme Chilliet
parent c2150bd079
commit 82ba7d763b
No known key found for this signature in database
GPG key ID: A3E2F658B28C760A

View file

@ -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 {