From 732badf552c91733192e87d6ceb2848b4b75d439 Mon Sep 17 00:00:00 2001 From: Carl Schwan Date: Tue, 18 Oct 2022 12:22:40 +0200 Subject: [PATCH] Additional type hinting found by psalm Signed-off-by: Carl Schwan --- apps/files_external/lib/Command/Create.php | 9 +++++---- apps/files_external/lib/Lib/Backend/Backend.php | 3 ++- .../lib/Lib/LegacyDependencyCheckPolyfill.php | 4 +++- apps/files_external/lib/Lib/Storage/AmazonS3.php | 2 +- apps/files_external/lib/Lib/StorageConfig.php | 8 ++++---- apps/files_external/lib/Service/DBConfigService.php | 6 +----- apps/files_external/templates/settings.php | 4 +++- build/psalm-baseline.xml | 8 ++++++++ 8 files changed, 27 insertions(+), 17 deletions(-) diff --git a/apps/files_external/lib/Command/Create.php b/apps/files_external/lib/Command/Create.php index 372fa4ef372..17e4731a2d6 100644 --- a/apps/files_external/lib/Command/Create.php +++ b/apps/files_external/lib/Command/Create.php @@ -34,6 +34,7 @@ use OCA\Files_External\Lib\StorageConfig; use OCA\Files_External\Service\BackendService; use OCA\Files_External\Service\GlobalStoragesService; use OCA\Files_External\Service\UserStoragesService; +use OCA\Files_External\Service\StoragesService; use OCP\IUserManager; use OCP\IUserSession; use Symfony\Component\Console\Input\ArrayInput; @@ -104,7 +105,7 @@ class Create extends Base { } protected function execute(InputInterface $input, OutputInterface $output): int { - $user = (string) $input->getOption('user'); + $user = (string)$input->getOption('user'); $mountPoint = $input->getArgument('mount_point'); $storageIdentifier = $input->getArgument('storage_backend'); $authIdentifier = $input->getArgument('authentication_backend'); @@ -172,7 +173,7 @@ class Create extends Base { return 0; } - private function validateParam($key, &$value, Backend $storageBackend, AuthMechanism $authBackend): bool { + private function validateParam(string $key, &$value, Backend $storageBackend, AuthMechanism $authBackend): bool { $params = array_merge($storageBackend->getParameters(), $authBackend->getParameters()); foreach ($params as $param) { /** @var DefinitionParameter $param */ @@ -186,7 +187,7 @@ class Create extends Base { return false; } - private function showMount($user, StorageConfig $mount, InputInterface $input, OutputInterface $output): void { + private function showMount(string $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')); @@ -194,7 +195,7 @@ class Create extends Base { $listCommand->listMounts($user, [$mount], $listInput, $output); } - protected function getStorageService(string $userId) { + protected function getStorageService(string $userId): StoragesService { if (!empty($userId)) { $user = $this->userManager->get($userId); if (is_null($user)) { diff --git a/apps/files_external/lib/Lib/Backend/Backend.php b/apps/files_external/lib/Lib/Backend/Backend.php index 845f51f5432..d0058e98b52 100644 --- a/apps/files_external/lib/Lib/Backend/Backend.php +++ b/apps/files_external/lib/Lib/Backend/Backend.php @@ -32,6 +32,7 @@ use OCA\Files_External\Lib\StorageModifierTrait; use OCA\Files_External\Lib\VisibilityTrait; use OCA\Files_External\Lib\IIdentifier; use OCA\Files_External\Lib\IFrontendDefinition; +use OCP\Files\Storage\IStorage; /** * Storage backend @@ -75,7 +76,7 @@ class Backend implements \JsonSerializable, IIdentifier, IFrontendDefinition { private $legacyAuthMechanism; /** - * @return string + * @return class-string */ public function getStorageClass() { return $this->storageClass; diff --git a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php index c2562e5c64e..42a72e960ea 100644 --- a/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php +++ b/apps/files_external/lib/Lib/LegacyDependencyCheckPolyfill.php @@ -21,13 +21,15 @@ */ namespace OCA\Files_External\Lib; +use OCP\Files\Storage\IStorage; + /** * Polyfill for checking dependencies using legacy Storage::checkDependencies() */ trait LegacyDependencyCheckPolyfill { /** - * @return string + * @return class-string */ abstract public function getStorageClass(); diff --git a/apps/files_external/lib/Lib/Storage/AmazonS3.php b/apps/files_external/lib/Lib/Storage/AmazonS3.php index 1b3d2e6936f..0424f337881 100644 --- a/apps/files_external/lib/Lib/Storage/AmazonS3.php +++ b/apps/files_external/lib/Lib/Storage/AmazonS3.php @@ -91,7 +91,7 @@ class AmazonS3 extends \OC\Files\Storage\Common { /** @var ICacheFactory $cacheFactory */ $cacheFactory = Server::get(ICacheFactory::class); $this->memCache = $cacheFactory->createLocal('s3-external'); - $this->logger = \OCP\Server::get(LoggerInterface::class); + $this->logger = Server::get(LoggerInterface::class); } /** diff --git a/apps/files_external/lib/Lib/StorageConfig.php b/apps/files_external/lib/Lib/StorageConfig.php index 20e5aea62d2..757f9d35bdb 100644 --- a/apps/files_external/lib/Lib/StorageConfig.php +++ b/apps/files_external/lib/Lib/StorageConfig.php @@ -126,17 +126,17 @@ class StorageConfig implements \JsonSerializable { /** * Creates a storage config * - * @param int|null $id config id or null for a new config + * @param int|string $id config id or null for a new config */ public function __construct($id = null) { - $this->id = $id; + $this->id = $id ?? -1; $this->mountOptions['enable_sharing'] = false; } /** * Returns the configuration id * - * @return int + * @retun int */ public function getId() { return $this->id; @@ -147,7 +147,7 @@ class StorageConfig implements \JsonSerializable { * * @param int $id configuration id */ - public function setId($id) { + public function setId(int $id): void { $this->id = $id; } diff --git a/apps/files_external/lib/Service/DBConfigService.php b/apps/files_external/lib/Service/DBConfigService.php index f6446eea363..bc089d18fbd 100644 --- a/apps/files_external/lib/Service/DBConfigService.php +++ b/apps/files_external/lib/Service/DBConfigService.php @@ -64,11 +64,7 @@ class DBConfigService { $this->crypto = $crypto; } - /** - * @param int $mountId - * @return array - */ - public function getMountById($mountId) { + public function getMountById(int $mountId): ?array { $builder = $this->connection->getQueryBuilder(); $query = $builder->select(['mount_id', 'mount_point', 'storage_backend', 'auth_backend', 'priority', 'type']) ->from('external_mounts', 'm') diff --git a/apps/files_external/templates/settings.php b/apps/files_external/templates/settings.php index d8dd91822c5..af7438e28d7 100644 --- a/apps/files_external/templates/settings.php +++ b/apps/files_external/templates/settings.php @@ -1,9 +1,11 @@ t("Enable encryption"); diff --git a/build/psalm-baseline.xml b/build/psalm-baseline.xml index 1b0dda5af75..795f34eda67 100644 --- a/build/psalm-baseline.xml +++ b/build/psalm-baseline.xml @@ -1104,6 +1104,14 @@ test + + + dispatch + + + dispatch + + addServiceListener -- 2.39.5