From 5d242aa2f86f003bb5f0400188a440d2d5eea68f Mon Sep 17 00:00:00 2001 From: Faraz Samapoor Date: Tue, 4 Jul 2023 22:13:32 +0330 Subject: Refactors files app commands. To improve code readability. Signed-off-by: Faraz Samapoor --- apps/files/lib/Command/ScanAppData.php | 60 ++++++++++++++-------------------- 1 file changed, 24 insertions(+), 36 deletions(-) (limited to 'apps/files/lib/Command/ScanAppData.php') diff --git a/apps/files/lib/Command/ScanAppData.php b/apps/files/lib/Command/ScanAppData.php index 63e13733b2a..ddd3986aa28 100644 --- a/apps/files/lib/Command/ScanAppData.php +++ b/apps/files/lib/Command/ScanAppData.php @@ -46,26 +46,20 @@ use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ScanAppData extends Base { + protected float $execTime = 0; - /** @var IRootFolder */ - protected $root; - /** @var IConfig */ - protected $config; - /** @var float */ - protected $execTime = 0; - /** @var int */ - protected $foldersCounter = 0; - /** @var int */ - protected $filesCounter = 0; - - public function __construct(IRootFolder $rootFolder, IConfig $config) { - parent::__construct(); + protected int $foldersCounter = 0; + + protected int $filesCounter = 0; - $this->root = $rootFolder; - $this->config = $config; + public function __construct( + protected IRootFolder $rootFolder, + protected IConfig $config, + ) { + parent::__construct(); } - protected function configure() { + protected function configure(): void { parent::configure(); $this @@ -80,7 +74,7 @@ class ScanAppData extends Base { $appData = $this->getAppDataFolder(); } catch (NotFoundException $e) { $output->writeln('NoAppData folder found'); - return 1; + return self::FAILURE; } if ($folder !== '') { @@ -88,7 +82,7 @@ class ScanAppData extends Base { $appData = $appData->get($folder); } catch (NotFoundException $e) { $output->writeln('Could not find folder: ' . $folder . ''); - return 1; + return self::FAILURE; } } @@ -126,21 +120,21 @@ class ScanAppData extends Base { } catch (ForbiddenException $e) { $output->writeln('Storage not writable'); $output->writeln('Make sure you\'re running the scan command only as the user the web server runs as'); - return 1; + return self::FAILURE; } catch (InterruptedException $e) { # exit the function if ctrl-c has been pressed $output->writeln('Interrupted by user'); - return 1; + return self::FAILURE; } catch (NotFoundException $e) { $output->writeln('Path not found: ' . $e->getMessage() . ''); - return 1; + return self::FAILURE; } catch (\Exception $e) { $output->writeln('Exception during scan: ' . $e->getMessage() . ''); $output->writeln('' . $e->getTraceAsString() . ''); - return 1; + return self::FAILURE; } - return 0; + return self::SUCCESS; } @@ -167,7 +161,7 @@ class ScanAppData extends Base { /** * Initialises some useful tools for the Command */ - protected function initTools() { + protected function initTools(): void { // Start the timer $this->execTime = -microtime(true); // Convert PHP errors to exceptions @@ -186,7 +180,7 @@ class ScanAppData extends Base { * * @throws \ErrorException */ - public function exceptionErrorHandler($severity, $message, $file, $line) { + public function exceptionErrorHandler($severity, $message, $file, $line): void { if (!(error_reporting() & $severity)) { // This error code is not included in error_reporting return; @@ -194,10 +188,7 @@ class ScanAppData extends Base { throw new \ErrorException($message, 0, $severity, $file, $line); } - /** - * @param OutputInterface $output - */ - protected function presentStats(OutputInterface $output) { + protected function presentStats(OutputInterface $output): void { // Stop the timer $this->execTime += microtime(true); @@ -213,9 +204,8 @@ class ScanAppData extends Base { * * @param string[] $headers * @param string[] $rows - * @param OutputInterface $output */ - protected function showSummary($headers, $rows, OutputInterface $output) { + protected function showSummary($headers, $rows, OutputInterface $output): void { $niceDate = $this->formatExecTime(); if (!$rows) { $rows = [ @@ -233,11 +223,9 @@ class ScanAppData extends Base { /** - * Formats microtime into a human readable format - * - * @return string + * Formats microtime into a human-readable format */ - protected function formatExecTime() { + protected function formatExecTime(): string { $secs = round($this->execTime); # convert seconds into HH:MM:SS form return sprintf('%02d:%02d:%02d', (int)($secs / 3600), ((int)($secs / 60) % 60), (int)$secs % 60); @@ -273,6 +261,6 @@ class ScanAppData extends Base { throw new NotFoundException(); } - return $this->root->get('appdata_'.$instanceId); + return $this->rootFolder->get('appdata_'.$instanceId); } } -- cgit v1.2.3