Skip to content

Commit

Permalink
refactor(objectstorage): cleanup types
Browse files Browse the repository at this point in the history
Signed-off-by: Thomas Citharel <[email protected]>
  • Loading branch information
tcitworld committed Oct 20, 2023
1 parent c98840c commit b756640
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,12 @@
namespace OC\Files\ObjectStore;

class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage {
/** @var string */
private $internalId;
private string $internalId;

/**
* @param array{internal-id: int|string} $params
* @throws \Exception
*/
public function __construct($params) {

Check failure on line 35 in lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php:35:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\AppdataPreviewObjectStoreStorage::__construct has the more specific type 'array{'internal-id': int|string}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage\IStorage::__construct (see https://psalm.dev/140)

Check failure on line 35 in lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php:35:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\AppdataPreviewObjectStoreStorage::__construct has the more specific type 'array{'internal-id': int|string}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage::__construct (see https://psalm.dev/140)
if (!isset($params['internal-id'])) {
throw new \Exception('missing id in parameters');
Expand All @@ -37,7 +40,7 @@ public function __construct($params) {
parent::__construct($params);

Check failure on line 40 in lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php:40:23: InvalidArgument: Argument 1 of OC\Files\ObjectStore\ObjectStoreStorage::__construct expects array{objectPrefix?: string, objectstore: OCP\Files\ObjectStore\IObjectStore, storageid?: string, validateWrites?: bool}, but array{'internal-id': int|string} with additional array shape fields (internal-id) was provided (see https://psalm.dev/004)
}

public function getId() {
public function getId(): string {
return 'object::appdata::preview:' . $this->internalId;
}
}
11 changes: 7 additions & 4 deletions lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
*/
namespace OC\Files\ObjectStore;

use Exception;
use OCP\Files\IHomeStorage;
use OCP\IUser;

Expand All @@ -34,17 +35,19 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage

/**
* The home user storage requires a user object to create a unique storage id
* @param array $params
*
* @param array{user: IUser} $params
* @throws Exception
*/
public function __construct($params) {

Check failure on line 42 in lib/private/Files/ObjectStore/HomeObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/HomeObjectStoreStorage.php:42:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\HomeObjectStoreStorage::__construct has the more specific type 'array{user: OCP\IUser}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage\IStorage::__construct (see https://psalm.dev/140)

Check failure on line 42 in lib/private/Files/ObjectStore/HomeObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/HomeObjectStoreStorage.php:42:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\HomeObjectStoreStorage::__construct has the more specific type 'array{user: OCP\IUser}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage::__construct (see https://psalm.dev/140)
if (! isset($params['user']) || ! $params['user'] instanceof IUser) {
throw new \Exception('missing user object in parameters');
throw new Exception('missing user object in parameters');
}
$this->user = $params['user'];
parent::__construct($params);

Check failure on line 47 in lib/private/Files/ObjectStore/HomeObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

InvalidArgument

lib/private/Files/ObjectStore/HomeObjectStoreStorage.php:47:23: InvalidArgument: Argument 1 of OC\Files\ObjectStore\ObjectStoreStorage::__construct expects array{objectPrefix?: string, objectstore: OCP\Files\ObjectStore\IObjectStore, storageid?: string, validateWrites?: bool}, but array{user: OCP\IUser} with additional array shape fields (user) was provided (see https://psalm.dev/004)
}

public function getId() {
public function getId(): string {
return 'object::user:' . $this->user->getUID();
}

Expand All @@ -54,7 +57,7 @@ public function getId() {
* @param string $path The path to get the owner
* @return false|string uid
*/
public function getOwner($path) {
public function getOwner($path): bool|string {
if (is_object($this->user)) {

Check failure on line 61 in lib/private/Files/ObjectStore/HomeObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

RedundantCondition

lib/private/Files/ObjectStore/HomeObjectStoreStorage.php:61:7: RedundantCondition: Type OCP\IUser for $this->user is always object (see https://psalm.dev/122)
return $this->user->getUID();
}
Expand Down
10 changes: 7 additions & 3 deletions lib/private/Files/ObjectStore/ObjectStoreStorage.php
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@
use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload;
use OCP\Files\Storage\IChunkedFileWrite;
use OCP\Files\Storage\IStorage;
use OCP\ILogger;

class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite {
use CopyDirectory;
Expand All @@ -55,11 +56,14 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
protected string $id;
private string $objectPrefix = 'urn:oid:';

private $logger;
private ILogger $logger;

/** @var bool */
protected $validateWrites = true;
protected bool $validateWrites = true;

/**
* @param array{objectstore: IObjectStore, storageid?: string, objectPrefix?: string, validateWrites?: bool} $params
* @throws \Exception
*/
public function __construct($params) {

Check failure on line 67 in lib/private/Files/ObjectStore/ObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/ObjectStoreStorage.php:67:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\ObjectStoreStorage::__construct has the more specific type 'array{objectPrefix?: string, objectstore: OCP\Files\ObjectStore\IObjectStore, storageid?: string, validateWrites?: bool}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage\IStorage::__construct (see https://psalm.dev/140)

Check failure on line 67 in lib/private/Files/ObjectStore/ObjectStoreStorage.php

View workflow job for this annotation

GitHub Actions / static-code-analysis

MoreSpecificImplementedParamType

lib/private/Files/ObjectStore/ObjectStoreStorage.php:67:30: MoreSpecificImplementedParamType: Argument 1 of OC\Files\ObjectStore\ObjectStoreStorage::__construct has the more specific type 'array{objectPrefix?: string, objectstore: OCP\Files\ObjectStore\IObjectStore, storageid?: string, validateWrites?: bool}', expecting 'array<array-key, mixed>' as defined by OCP\Files\Storage::__construct (see https://psalm.dev/140)
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
$this->objectStore = $params['objectstore'];
Expand Down
4 changes: 2 additions & 2 deletions tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,15 +30,15 @@
* Allow overwriting the object store instance for test purposes
*/
class ObjectStoreStorageOverwrite extends ObjectStoreStorage {
public function setObjectStore(IObjectStore $objectStore) {
public function setObjectStore(IObjectStore $objectStore): void {
$this->objectStore = $objectStore;
}

public function getObjectStore(): IObjectStore {
return $this->objectStore;
}

public function setValidateWrites(bool $validate) {
public function setValidateWrites(bool $validate): void {
$this->validateWrites = $validate;
}
}

0 comments on commit b756640

Please sign in to comment.