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/Object/Get.php | 41 +++++++++++++++++------------------ 1 file changed, 20 insertions(+), 21 deletions(-) (limited to 'apps/files/lib/Command/Object/Get.php') 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("Object $object does not exist"); - return 1; - } else { - try { - $source = $objectStore->readObject($object); - } catch (\Exception $e) { - $msg = $e->getMessage(); - $output->writeln("Failed to read $object from object store: $msg"); - return 1; - } - $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w'); - if (!$target) { - $output->writeln("Failed to open $outputName for writing"); - 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("Failed to read $object from object store: $msg"); + return self::FAILURE; } + $target = $outputName === '-' ? STDOUT : fopen($outputName, 'w'); + if (!$target) { + $output->writeln("Failed to open $outputName for writing"); + return self::FAILURE; + } + + stream_copy_to_stream($source, $target); + return self::SUCCESS; } } -- cgit v1.2.3