]> source.dussan.org Git - nextcloud-server.git/commitdiff
Add more typing to FilesExternal commands
authorCarl Schwan <carl@carlschwan.eu>
Sun, 16 Oct 2022 22:54:00 +0000 (00:54 +0200)
committerCarl Schwan <carl@carlschwan.eu>
Mon, 17 Oct 2022 08:58:25 +0000 (10:58 +0200)
Signed-off-by: Carl Schwan <carl@carlschwan.eu>
apps/files_external/lib/Command/Applicable.php
apps/files_external/lib/Command/Backends.php
apps/files_external/lib/Command/Config.php
apps/files_external/lib/Command/Create.php
apps/files_external/lib/Command/Delete.php
apps/files_external/lib/Command/Export.php
apps/files_external/lib/Command/Import.php
apps/files_external/lib/Command/ListCommand.php
apps/files_external/lib/Command/Notify.php
apps/files_external/lib/Command/Option.php
apps/files_external/lib/Command/Verify.php

index 29d5459200e30423c035560c5e2febdf0cafbb1d..a3708602dff8e836c4ce1eab1aabc99bff38fc27 100644 (file)
@@ -36,20 +36,9 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Applicable extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       protected $globalService;
-
-       /**
-        * @var IUserManager
-        */
-       private $userManager;
-
-       /**
-        * @var IGroupManager
-        */
-       private $groupManager;
+       protected GlobalStoragesService $globalService;
+       private IUserManager $userManager;
+       private IGroupManager $groupManager;
 
        public function __construct(
                GlobalStoragesService $globalService,
@@ -62,7 +51,7 @@ class Applicable extends Base {
                $this->groupManager = $groupManager;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:applicable')
                        ->setDescription('Manage applicable users and groups for a mount')
index 60d035f997f9dda378d895ffd8c7958d64731bec..faf6209bd74b8662a7bb4f387685aea4013d680b 100644 (file)
@@ -33,8 +33,7 @@ use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Backends extends Base {
-       /** @var BackendService */
-       private $backendService;
+       private BackendService $backendService;
 
        public function __construct(BackendService $backendService
        ) {
@@ -43,7 +42,7 @@ class Backends extends Base {
                $this->backendService = $backendService;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:backends')
                        ->setDescription('Show available authentication and storage backends')
index 5d0675b04bc9d9b0ad810806db97b264eeba1dbc..1107bfb4d423c082d0d4bc9fe0ed333797523ce9 100644 (file)
@@ -33,17 +33,14 @@ use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Config extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       protected $globalService;
+       protected GlobalStoragesService $globalService;
 
        public function __construct(GlobalStoragesService $globalService) {
                parent::__construct();
                $this->globalService = $globalService;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:config')
                        ->setDescription('Manage backend configuration for a mount')
index 99991b893cdab53dc122166622c5789bfbe31de0..372fa4ef372677622ad8cb8aa1d21a9bf3de0d2a 100644 (file)
@@ -43,26 +43,11 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Create extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       private $globalService;
-
-       /**
-        * @var UserStoragesService
-        */
-       private $userService;
-
-       /**
-        * @var IUserManager
-        */
-       private $userManager;
-
-       /** @var BackendService */
-       private $backendService;
-
-       /** @var IUserSession */
-       private $userSession;
+       private GlobalStoragesService $globalService;
+       private UserStoragesService $userService;
+       private IUserManager $userManager;
+       private BackendService $backendService;
+       private IUserSession $userSession;
 
        public function __construct(GlobalStoragesService $globalService,
                                                 UserStoragesService $userService,
@@ -78,7 +63,7 @@ class Create extends Base {
                $this->backendService = $backendService;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:create')
                        ->setDescription('Create a new mount configuration')
@@ -187,7 +172,7 @@ class Create extends Base {
                return 0;
        }
 
-       private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend) {
+       private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend): bool {
                $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters());
                foreach ($params as $param) {
                        /** @var DefinitionParameter $param */
@@ -201,7 +186,7 @@ class Create extends Base {
                return false;
        }
 
-       private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output) {
+       private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output): void {
                $listCommand = new ListCommand($this->globalService, $this->userService, $this->userSession, $this->userManager);
                $listInput = new ArrayInput([], $listCommand->getDefinition());
                $listInput->setOption('output', $input->getOption('output'));
@@ -209,7 +194,7 @@ class Create extends Base {
                $listCommand->listMounts($user, [$mount], $listInput, $output);
        }
 
-       protected function getStorageService($userId) {
+       protected function getStorageService(string $userId) {
                if (!empty($userId)) {
                        $user = $this->userManager->get($userId);
                        if (is_null($user)) {
index a41161792b53cd850c4bbfbc0d9205003cb35aab..cf09e3907b72cc46f67521877f8a143d21aba1db 100644 (file)
@@ -37,25 +37,10 @@ use Symfony\Component\Console\Output\OutputInterface;
 use Symfony\Component\Console\Question\ConfirmationQuestion;
 
 class Delete extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       protected $globalService;
-
-       /**
-        * @var UserStoragesService
-        */
-       protected $userService;
-
-       /**
-        * @var IUserSession
-        */
-       protected $userSession;
-
-       /**
-        * @var IUserManager
-        */
-       protected $userManager;
+       protected GlobalStoragesService $globalService;
+       protected UserStoragesService $userService;
+       protected IUserSession $userSession;
+       protected IUserManager $userManager;
 
        public function __construct(GlobalStoragesService $globalService, UserStoragesService $userService, IUserSession $userSession, IUserManager $userManager) {
                parent::__construct();
@@ -65,7 +50,7 @@ class Delete extends Base {
                $this->userManager = $userManager;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:delete')
                        ->setDescription('Delete an external mount')
index 622c4b460785f03d40b6704d444521fe72f68934..98cfb6830602186f7a649457b9b4f31ecae40652 100644 (file)
@@ -29,7 +29,7 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Export extends ListCommand {
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:export')
                        ->setDescription('Export mount configurations')
index 53ae0d7c5bf88a00232d15d91346b5cc45882af2..eab7dd9a6bedb3f0c7a45be7594864a0b8e1b7c5 100644 (file)
@@ -40,31 +40,12 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Import extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       private $globalService;
-
-       /**
-        * @var UserStoragesService
-        */
-       private $userService;
-
-       /**
-        * @var IUserSession
-        */
-       private $userSession;
-
-       /**
-        * @var IUserManager
-        */
-       private $userManager;
-
-       /** @var ImportLegacyStoragesService */
-       private $importLegacyStorageService;
-
-       /** @var BackendService */
-       private $backendService;
+       private GlobalStoragesService $globalService;
+       private UserStoragesService $userService;
+       private IUserSession $userSession;
+       private IUserManager $userManager;
+       private ImportLegacyStoragesService $importLegacyStorageService;
+       private BackendService $backendService;
 
        public function __construct(GlobalStoragesService $globalService,
                                                 UserStoragesService $userService,
@@ -82,7 +63,7 @@ class Import extends Base {
                $this->backendService = $backendService;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:import')
                        ->setDescription('Import mount configurations')
@@ -189,7 +170,7 @@ class Import extends Base {
                return 0;
        }
 
-       private function parseData(array $data) {
+       private function parseData(array $data): StorageConfig {
                $mount = new StorageConfig($data['mount_id']);
                $mount->setMountPoint($data['mount_point']);
                $mount->setBackend($this->getBackendByClass($data['storage']));
@@ -202,7 +183,7 @@ class Import extends Base {
                return $mount;
        }
 
-       private function getBackendByClass($className) {
+       private function getBackendByClass(string $className) {
                $backends = $this->backendService->getBackends();
                foreach ($backends as $backend) {
                        if ($backend->getStorageClass() === $className) {
index 461991c073b7c655a95968a074e7930268a4362c..b2a4baf366b8af7c52e12fadede75507eb633b5e 100644 (file)
@@ -39,25 +39,10 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class ListCommand extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       protected $globalService;
-
-       /**
-        * @var UserStoragesService
-        */
-       protected $userService;
-
-       /**
-        * @var IUserSession
-        */
-       protected $userSession;
-
-       /**
-        * @var IUserManager
-        */
-       protected $userManager;
+       protected GlobalStoragesService $globalService;
+       protected UserStoragesService $userService;
+       protected IUserSession $userSession;
+       protected IUserManager $userManager;
 
        public const ALL = -1;
 
@@ -69,7 +54,7 @@ class ListCommand extends Base {
                $this->userManager = $userManager;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:list')
                        ->setDescription('List configured admin or personal mounts')
@@ -102,7 +87,7 @@ class ListCommand extends Base {
                        $mounts = $this->globalService->getStorageForAllUsers();
                        $userId = self::ALL;
                } else {
-                       $userId = $input->getArgument('user_id');
+                       $userId = (string)$input->getArgument('user_id');
                        $storageService = $this->getStorageService($userId);
                        $mounts = $storageService->getAllStorages();
                }
@@ -114,10 +99,8 @@ class ListCommand extends Base {
        /**
         * @param ?string|ListCommand::ALL $userId
         * @param StorageConfig[] $mounts
-        * @param InputInterface $input
-        * @param OutputInterface $output
         */
-       public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output) {
+       public function listMounts($userId, array $mounts, InputInterface $input, OutputInterface $output): void {
                $outputType = $input->getOption('output');
                if (count($mounts) === 0) {
                        if ($outputType === self::OUTPUT_FORMAT_JSON || $outputType === self::OUTPUT_FORMAT_JSON_PRETTY) {
index 2e3ade7df7abe5cad4b7ece6b38c74a707102ef3..bba698fb25f192aaf47cd57646ff41d69c9aefb1 100644 (file)
@@ -39,27 +39,24 @@ use OCP\Files\Storage\INotifyStorage;
 use OCP\Files\Storage\IStorage;
 use OCP\Files\StorageNotAvailableException;
 use OCP\IDBConnection;
-use OCP\ILogger;
 use OCP\IUserManager;
+use Psr\Log\LoggerInterface;
 use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Input\InputInterface;
 use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Notify extends Base {
-       /** @var GlobalStoragesService */
-       private $globalService;
-       /** @var IDBConnection */
-       private $connection;
-       /** @var ILogger */
-       private $logger;
+       private GlobalStoragesService $globalService;
+       private IDBConnection $connection;
+       private LoggerInterface $logger;
        /** @var IUserManager */
        private $userManager;
 
        public function __construct(
                GlobalStoragesService $globalService,
                IDBConnection $connection,
-               ILogger $logger,
+               LoggerInterface $logger,
                IUserManager $userManager
        ) {
                parent::__construct();
@@ -69,7 +66,7 @@ class Notify extends Base {
                $this->userManager = $userManager;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:notify')
                        ->setDescription('Listen for active update notifications for a configured external mount')
@@ -207,7 +204,7 @@ class Notify extends Base {
                return 0;
        }
 
-       private function createStorage(StorageConfig $mount) {
+       private function createStorage(StorageConfig $mount): IStorage {
                $class = $mount->getBackend()->getStorageClass();
                return new $class($mount->getBackendOptions());
        }
@@ -221,7 +218,7 @@ class Notify extends Base {
                try {
                        $storages = $this->getStorageIds($mountId, $parent);
                } catch (DriverException $ex) {
-                       $this->logger->logException($ex, ['message' => 'Error while trying to find correct storage ids.', 'level' => ILogger::WARN]);
+                       $this->logger->warning('Error while trying to find correct storage ids.', ['exception' => $ex]);
                        $this->connection = $this->reconnectToDatabase($this->connection, $output);
                        $output->writeln('<info>Needed to reconnect to the database</info>');
                        $storages = $this->getStorageIds($mountId, $path);
@@ -307,7 +304,7 @@ class Notify extends Base {
                try {
                        $connection->close();
                } catch (\Exception $ex) {
-                       $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while disconnecting from DB', 'level' => ILogger::WARN]);
+                       $this->logger->warning('Error while disconnecting from DB', ['exception' => $ex]);
                        $output->writeln("<info>Error while disconnecting from database: {$ex->getMessage()}</info>");
                }
                $connected = false;
@@ -315,7 +312,7 @@ class Notify extends Base {
                        try {
                                $connected = $connection->connect();
                        } catch (\Exception $ex) {
-                               $this->logger->logException($ex, ['app' => 'files_external', 'message' => 'Error while re-connecting to database', 'level' => ILogger::WARN]);
+                               $this->logger->warning('Error while re-connecting to database', ['exception' => $ex]);
                                $output->writeln("<info>Error while re-connecting to database: {$ex->getMessage()}</info>");
                                sleep(60);
                        }
index 9f7d4a30bcd437561f0b2852dfffbc765f3c37af..30390ebabee47c4f9134b96767430bd36caec2f8 100644 (file)
@@ -27,7 +27,7 @@ use Symfony\Component\Console\Input\InputArgument;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Option extends Config {
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:option')
                        ->setDescription('Manage mount options for a mount')
index 0febfa15825a9ac49ece09807ffe3e8f4628ae81..f8079ec4d6500af1cdd94c4ede301c69b7a50036 100644 (file)
@@ -38,17 +38,14 @@ use Symfony\Component\Console\Input\InputOption;
 use Symfony\Component\Console\Output\OutputInterface;
 
 class Verify extends Base {
-       /**
-        * @var GlobalStoragesService
-        */
-       protected $globalService;
+       protected GlobalStoragesService $globalService;
 
        public function __construct(GlobalStoragesService $globalService) {
                parent::__construct();
                $this->globalService = $globalService;
        }
 
-       protected function configure() {
+       protected function configure(): void {
                $this
                        ->setName('files_external:verify')
                        ->setDescription('Verify mount configuration')