diff options
author | Faraz Samapoor <f.samapoor@gmail.com> | 2023-07-04 22:13:32 +0330 |
---|---|---|
committer | Faraz Samapoor <fsa@adlas.at> | 2023-07-12 18:29:32 +0330 |
commit | 5d242aa2f86f003bb5f0400188a440d2d5eea68f (patch) | |
tree | 514599caddf25a0b6d8414ce510f7b4c41f03b62 /apps/files/lib/Command/Object/Get.php | |
parent | 706c141fffce928d344fe2f039da549fad065393 (diff) | |
download | nextcloud-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/Object/Get.php')
-rw-r--r-- | apps/files/lib/Command/Object/Get.php | 41 |
1 files changed, 20 insertions, 21 deletions
diff --git a/apps/files/lib/Command/Object/Get.php b/apps/files/lib/Command/Object/Get.php index c07a64b20e2..cad1f3d98ac 100644 --- a/apps/files/lib/Command/Object/Get.php +++ b/apps/files/lib/Command/Object/Get.php @@ -31,10 +31,9 @@ use Symfony\Component\Console\Input\InputOption; use Symfony\Component\Console\Output\OutputInterface; class Get extends Command { - private ObjectUtil $objectUtils; - - public function __construct(ObjectUtil $objectUtils) { - $this->objectUtils = $objectUtils; + public function __construct( + private ObjectUtil $objectUtils, + ) { parent::__construct(); } @@ -52,29 +51,29 @@ class Get extends Command { $outputName = $input->getArgument('output'); $objectStore = $this->objectUtils->getObjectStore($input->getOption("bucket"), $output); if (!$objectStore) { - return 1; + return self::FAILURE; } if (!$objectStore->objectExists($object)) { $output->writeln("<error>Object $object does not exist</error>"); - return 1; - } else { - try { - $source = $objectStore->readObject($object); - } catch (\Exception $e) { - $msg = $e->getMessage(); - $output->writeln("<error>Failed to read $object from object store: $msg</error>"); - return 1; - } - $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w'); - if (!$target) { - $output->writeln("<error>Failed to open $outputName for writing</error>"); - return 1; - } + return self::FAILURE; + } - stream_copy_to_stream($source, $target); - return 0; + try { + $source = $objectStore->readObject($object); + } catch (\Exception $e) { + $msg = $e->getMessage(); + $output->writeln("<error>Failed to read $object from object store: $msg</error>"); + return self::FAILURE; } + $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w'); + if (!$target) { + $output->writeln("<error>Failed to open $outputName for writing</error>"); + return self::FAILURE; + } + + stream_copy_to_stream($source, $target); + return self::SUCCESS; } } |