refactor(objectstorage): cleanup types

Signed-off-by: Thomas Citharel <tcit@tcit.fr>
pull/40981/head
Thomas Citharel 1 year ago
parent 3be3dbdb3b
commit 30798eb6c2
No known key found for this signature in database
GPG Key ID: A061B9DDE0CA0773
  1. 9
      lib/private/Files/ObjectStore/AppdataPreviewObjectStoreStorage.php
  2. 16
      lib/private/Files/ObjectStore/HomeObjectStoreStorage.php
  3. 11
      lib/private/Files/ObjectStore/ObjectStoreStorage.php
  4. 4
      tests/lib/Files/ObjectStore/ObjectStoreStorageOverwrite.php

@ -26,9 +26,12 @@ declare(strict_types=1);
namespace OC\Files\ObjectStore; namespace OC\Files\ObjectStore;
class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage { class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage {
/** @var string */ private string $internalId;
private $internalId;
/**
* @param array $params
* @throws \Exception
*/
public function __construct($params) { public function __construct($params) {
if (!isset($params['internal-id'])) { if (!isset($params['internal-id'])) {
throw new \Exception('missing id in parameters'); throw new \Exception('missing id in parameters');
@ -37,7 +40,7 @@ class AppdataPreviewObjectStoreStorage extends ObjectStoreStorage {
parent::__construct($params); parent::__construct($params);
} }
public function getId() { public function getId(): string {
return 'object::appdata::preview:' . $this->internalId; return 'object::appdata::preview:' . $this->internalId;
} }
} }

@ -26,6 +26,7 @@
*/ */
namespace OC\Files\ObjectStore; namespace OC\Files\ObjectStore;
use Exception;
use OCP\Files\IHomeStorage; use OCP\Files\IHomeStorage;
use OCP\IUser; use OCP\IUser;
@ -34,17 +35,19 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage
/** /**
* The home user storage requires a user object to create a unique storage id * The home user storage requires a user object to create a unique storage id
*
* @param array $params * @param array $params
* @throws Exception
*/ */
public function __construct($params) { public function __construct($params) {
if (! isset($params['user']) || ! $params['user'] instanceof IUser) { 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']; $this->user = $params['user'];
parent::__construct($params); parent::__construct($params);
} }
public function getId() { public function getId(): string {
return 'object::user:' . $this->user->getUID(); return 'object::user:' . $this->user->getUID();
} }
@ -52,13 +55,10 @@ class HomeObjectStoreStorage extends ObjectStoreStorage implements IHomeStorage
* get the owner of a path * get the owner of a path
* *
* @param string $path The path to get the owner * @param string $path The path to get the owner
* @return false|string uid * @return string uid
*/ */
public function getOwner($path) { public function getOwner($path): string {
if (is_object($this->user)) { return $this->user->getUID();
return $this->user->getUID();
}
return false;
} }
public function getUser(): IUser { public function getUser(): IUser {

@ -47,6 +47,7 @@ use OCP\Files\ObjectStore\IObjectStore;
use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload; use OCP\Files\ObjectStore\IObjectStoreMultiPartUpload;
use OCP\Files\Storage\IChunkedFileWrite; use OCP\Files\Storage\IChunkedFileWrite;
use OCP\Files\Storage\IStorage; use OCP\Files\Storage\IStorage;
use OCP\ILogger;
class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite { class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFileWrite {
use CopyDirectory; use CopyDirectory;
@ -55,13 +56,15 @@ class ObjectStoreStorage extends \OC\Files\Storage\Common implements IChunkedFil
protected string $id; protected string $id;
private string $objectPrefix = 'urn:oid:'; private string $objectPrefix = 'urn:oid:';
private $logger; private ILogger $logger;
private bool $handleCopiesAsOwned; private bool $handleCopiesAsOwned;
protected bool $validateWrites = true;
/** @var bool */ /**
protected $validateWrites = true; * @param array $params
* @throws \Exception
*/
public function __construct($params) { public function __construct($params) {
if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) { if (isset($params['objectstore']) && $params['objectstore'] instanceof IObjectStore) {
$this->objectStore = $params['objectstore']; $this->objectStore = $params['objectstore'];

@ -30,7 +30,7 @@ use OCP\Files\ObjectStore\IObjectStore;
* Allow overwriting the object store instance for test purposes * Allow overwriting the object store instance for test purposes
*/ */
class ObjectStoreStorageOverwrite extends ObjectStoreStorage { class ObjectStoreStorageOverwrite extends ObjectStoreStorage {
public function setObjectStore(IObjectStore $objectStore) { public function setObjectStore(IObjectStore $objectStore): void {
$this->objectStore = $objectStore; $this->objectStore = $objectStore;
} }
@ -38,7 +38,7 @@ class ObjectStoreStorageOverwrite extends ObjectStoreStorage {
return $this->objectStore; return $this->objectStore;
} }
public function setValidateWrites(bool $validate) { public function setValidateWrites(bool $validate): void {
$this->validateWrites = $validate; $this->validateWrites = $validate;
} }
} }

Loading…
Cancel
Save