more type hints for ICachedMountInfo and IMountManager

Signed-off-by: Robin Appelman <robin@icewind.nl>
pull/31431/head
Robin Appelman 2022-02-10 14:15:07 +07:00
parent 69a6efba47
commit 7630d7a934
No known key found for this signature in database
GPG Key ID: 42B69D8A64526EFB
7 changed files with 46 additions and 74 deletions

@ -27,8 +27,7 @@ use OCP\Files\Config\ICachedMountFileInfo;
use OCP\IUser;
class CachedMountFileInfo extends CachedMountInfo implements ICachedMountFileInfo {
/** @var string */
private $internalPath;
private string $internalPath;
public function __construct(
IUser $user,

@ -28,38 +28,13 @@ use OCP\Files\Node;
use OCP\IUser;
class CachedMountInfo implements ICachedMountInfo {
/**
* @var IUser
*/
protected $user;
/**
* @var int
*/
protected $storageId;
/**
* @var int
*/
protected $rootId;
/**
* @var string
*/
protected $mountPoint;
/**
* @var int|null
*/
protected $mountId;
/**
* @var string
*/
protected $rootInternalPath;
/** @var string */
protected $mountProvider;
protected IUser $user;
protected int $storageId;
protected int $rootId;
protected string $mountPoint;
protected ?int $mountId;
protected string $rootInternalPath;
protected string $mountProvider;
/**
* CachedMountInfo constructor.
@ -95,28 +70,28 @@ class CachedMountInfo implements ICachedMountInfo {
/**
* @return IUser
*/
public function getUser() {
public function getUser(): IUser {
return $this->user;
}
/**
* @return int the numeric storage id of the mount
*/
public function getStorageId() {
public function getStorageId(): int {
return $this->storageId;
}
/**
* @return int the fileid of the root of the mount
*/
public function getRootId() {
public function getRootId(): int {
return $this->rootId;
}
/**
* @return Node the root node of the mount
* @return Node|null the root node of the mount
*/
public function getMountPointNode() {
public function getMountPointNode(): ?Node {
// TODO injection etc
Filesystem::initMountPoints($this->getUser()->getUID());
$userNode = \OC::$server->getUserFolder($this->getUser()->getUID());
@ -131,7 +106,7 @@ class CachedMountInfo implements ICachedMountInfo {
/**
* @return string the mount point of the mount for the user
*/
public function getMountPoint() {
public function getMountPoint(): string {
return $this->mountPoint;
}
@ -141,7 +116,7 @@ class CachedMountInfo implements ICachedMountInfo {
* @return int|null mount id or null if not applicable
* @since 9.1.0
*/
public function getMountId() {
public function getMountId(): ?int {
return $this->mountId;
}
@ -150,7 +125,7 @@ class CachedMountInfo implements ICachedMountInfo {
*
* @return string
*/
public function getRootInternalPath() {
public function getRootInternalPath(): string {
return $this->rootInternalPath;
}

@ -25,8 +25,7 @@ use OCP\Files\Mount\IMountPoint;
use OCP\IUser;
class LazyStorageMountInfo extends CachedMountInfo {
/** @var IMountPoint */
private $mount;
private IMountPoint $mount;
/**
* CachedMountInfo constructor.
@ -37,12 +36,15 @@ class LazyStorageMountInfo extends CachedMountInfo {
public function __construct(IUser $user, IMountPoint $mount) {
$this->user = $user;
$this->mount = $mount;
$this->rootId = 0;
$this->storageId = 0;
$this->mountPoint = '';
}
/**
* @return int the numeric storage id of the mount
*/
public function getStorageId() {
public function getStorageId(): int {
if (!$this->storageId) {
$this->storageId = $this->mount->getNumericStorageId();
}
@ -52,7 +54,7 @@ class LazyStorageMountInfo extends CachedMountInfo {
/**
* @return int the fileid of the root of the mount
*/
public function getRootId() {
public function getRootId(): int {
if (!$this->rootId) {
$this->rootId = $this->mount->getStorageRootId();
}
@ -62,14 +64,14 @@ class LazyStorageMountInfo extends CachedMountInfo {
/**
* @return string the mount point of the mount for the user
*/
public function getMountPoint() {
public function getMountPoint(): string {
if (!$this->mountPoint) {
$this->mountPoint = $this->mount->getMountPoint();
}
return parent::getMountPoint();
}
public function getMountId() {
public function getMountId(): ?int {
return $this->mount->getMountId();
}
@ -78,7 +80,7 @@ class LazyStorageMountInfo extends CachedMountInfo {
*
* @return string
*/
public function getRootInternalPath() {
public function getRootInternalPath(): string {
return $this->mount->getInternalPath($this->mount->getMountPoint());
}

@ -35,13 +35,9 @@ use OCP\Files\Mount\IMountPoint;
class Manager implements IMountManager {
/** @var MountPoint[] */
private $mounts = [];
/** @var CappedMemoryCache */
private $pathCache;
/** @var CappedMemoryCache */
private $inPathCache;
private array $mounts = [];
private CappedMemoryCache $pathCache;
private CappedMemoryCache $inPathCache;
public function __construct() {
$this->pathCache = new CappedMemoryCache();
@ -99,7 +95,7 @@ class Manager implements IMountManager {
* @param string $path
* @return MountPoint|null
*/
public function find(string $path) {
public function find(string $path): ?MountPoint {
$this->setupForFind($path);
$path = Filesystem::normalizePath($path);

@ -34,11 +34,11 @@ interface ICachedMountFileInfo extends ICachedMountInfo {
* @return string
* @since 13.0.0
*/
public function getInternalPath();
public function getInternalPath(): string;
/**
* @return string
* @since 13.0.0
*/
public function getPath();
public function getPath(): string;
}

@ -35,31 +35,31 @@ interface ICachedMountInfo {
* @return IUser
* @since 9.0.0
*/
public function getUser();
public function getUser(): IUser;
/**
* @return int the numeric storage id of the mount
* @since 9.0.0
*/
public function getStorageId();
public function getStorageId(): int;
/**
* @return int the fileid of the root of the mount
* @since 9.0.0
*/
public function getRootId();
public function getRootId(): int;
/**
* @return Node the root node of the mount
* @return Node|null the root node of the mount
* @since 9.0.0
*/
public function getMountPointNode();
public function getMountPointNode(): ?Node;
/**
* @return string the mount point of the mount for the user
* @since 9.0.0
*/
public function getMountPoint();
public function getMountPoint(): string;
/**
* Get the id of the configured mount
@ -67,7 +67,7 @@ interface ICachedMountInfo {
* @return int|null mount id or null if not applicable
* @since 9.1.0
*/
public function getMountId();
public function getMountId(): ?int;
/**
* Get the internal path (within the storage) of the root of the mount
@ -75,7 +75,7 @@ interface ICachedMountInfo {
* @return string
* @since 11.0.0
*/
public function getRootInternalPath();
public function getRootInternalPath(): string;
/**
* Get the class of the mount provider that this mount originates from

@ -37,7 +37,7 @@ interface IMountManager {
/**
* Add a new mount
*
* @param \OCP\Files\Mount\IMountPoint $mount
* @param IMountPoint $mount
* @since 8.2.0
*/
public function addMount(IMountPoint $mount);
@ -63,16 +63,16 @@ interface IMountManager {
* Find the mount for $path
*
* @param string $path
* @return \OCP\Files\Mount\IMountPoint|null
* @return IMountPoint|null
* @since 8.2.0
*/
public function find(string $path);
public function find(string $path): ?IMountPoint;
/**
* Find all mounts in $path
*
* @param string $path
* @return \OCP\Files\Mount\IMountPoint[]
* @return IMountPoint[]
* @since 8.2.0
*/
public function findIn(string $path): array;
@ -88,13 +88,13 @@ interface IMountManager {
* Find mounts by storage id
*
* @param string $id
* @return \OCP\Files\Mount\IMountPoint[]
* @return IMountPoint[]
* @since 8.2.0
*/
public function findByStorageId(string $id): array;
/**
* @return \OCP\Files\Mount\IMountPoint[]
* @return IMountPoint[]
* @since 8.2.0
*/
public function getAll(): array;
@ -103,7 +103,7 @@ interface IMountManager {
* Find mounts by numeric storage id
*
* @param int $id
* @return \OCP\Files\Mount\IMountPoint[]
* @return IMountPoint[]
* @since 8.2.0
*/
public function findByNumericId(int $id): array;