aboutsummaryrefslogtreecommitdiffstats
path: root/apps/files/lib/Command/ScanAppData.php
diff options
context:
space:
mode:
authorFaraz Samapoor <f.samapoor@gmail.com>2023-07-04 22:13:32 +0330
committerFaraz Samapoor <fsa@adlas.at>2023-07-12 18:29:32 +0330
commit5d242aa2f86f003bb5f0400188a440d2d5eea68f (patch)
tree514599caddf25a0b6d8414ce510f7b4c41f03b62 /apps/files/lib/Command/ScanAppData.php
parent706c141fffce928d344fe2f039da549fad065393 (diff)
downloadnextcloud-server-5d242aa2f86f003bb5f0400188a440d2d5eea68f.tar.gz
nextcloud-server-5d242aa2f86f003bb5f0400188a440d2d5eea68f.zip
Refactors files app commands.
To improve code readability. Signed-off-by: Faraz Samapoor <fsa@adlas.at>
Diffstat (limited to 'apps/files/lib/Command/ScanAppData.php')
-rw-r--r--apps/files/lib/Command/ScanAppData.php60
1 files changed, 24 insertions, 36 deletions
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('<error>NoAppData folder found</error>');
- return 1;
+ return self::FAILURE;
}
if ($folder !== '') {
@@ -88,7 +82,7 @@ class ScanAppData extends Base {
$appData = $appData->get($folder);
} catch (NotFoundException $e) {
$output->writeln('<error>Could not find folder: ' . $folder . '</error>');
- return 1;
+ return self::FAILURE;
}
}
@@ -126,21 +120,21 @@ class ScanAppData extends Base {
} catch (ForbiddenException $e) {
$output->writeln('<error>Storage not writable</error>');
$output->writeln('<info>Make sure you\'re running the scan command only as the user the web server runs as</info>');
- return 1;
+ return self::FAILURE;
} catch (InterruptedException $e) {
# exit the function if ctrl-c has been pressed
$output->writeln('<info>Interrupted by user</info>');
- return 1;
+ return self::FAILURE;
} catch (NotFoundException $e) {
$output->writeln('<error>Path not found: ' . $e->getMessage() . '</error>');
- return 1;
+ return self::FAILURE;
} catch (\Exception $e) {
$output->writeln('<error>Exception during scan: ' . $e->getMessage() . '</error>');
$output->writeln('<error>' . $e->getTraceAsString() . '</error>');
- 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);
}
}