Skip to content
Prev Previous commit
Next Next commit
chore: Code cleanup in lib/private/Console/Application
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld authored and come-nc committed Sep 10, 2024
commit 82ba7d763bb5fe2fea67df0475ba2516389575ae
25 changes: 15 additions & 10 deletions lib/private/Console/Application.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -33,8 +37,8 @@ public function __construct(
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());
}

Expand All @@ -44,7 +48,7 @@ public function __construct(
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();
Expand Down Expand Up @@ -118,7 +122,7 @@ public function loadCommands(
$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');
Expand All @@ -127,7 +131,7 @@ public function loadCommands(
}

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']);
Expand Down Expand Up @@ -163,13 +167,11 @@ private function writeMaintenanceModeInfo(InputInterface $input, ConsoleOutputIn
*
* @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
*/
Expand All @@ -183,15 +185,18 @@ public function run(?InputInterface $input = null, ?OutputInterface $output = nu
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 {
Expand Down