summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorCarl Schwan <carl@carlschwan.eu>2022-07-18 12:34:11 +0200
committerGitHub <noreply@github.com>2022-07-18 12:34:11 +0200
commit6c3c7a5e4da693f91fa4abf7f2495ff479ad42a0 (patch)
treecd3fe8c71fad7334f0fe716cb099950d6f2ebd94 /lib
parent929aaaa129519e554f56b19815d0e2ff0f41cd2b (diff)
parent19a36b58a69f9a8cc31da213657fdf828d9fdb3c (diff)
downloadnextcloud-server-6c3c7a5e4da693f91fa4abf7f2495ff479ad42a0.tar.gz
nextcloud-server-6c3c7a5e4da693f91fa4abf7f2495ff479ad42a0.zip
Merge pull request #32981 from nextcloud/typing/carl/simplefs
Add typing to SimpleFS
Diffstat (limited to 'lib')
-rw-r--r--lib/private/Files/SimpleFS/NewSimpleFile.php36
-rw-r--r--lib/private/Files/SimpleFS/SimpleFile.php42
-rw-r--r--lib/private/Files/SimpleFS/SimpleFolder.php13
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFile.php22
-rw-r--r--lib/public/Files/SimpleFS/ISimpleFolder.php17
-rw-r--r--lib/public/Files/SimpleFS/ISimpleRoot.php4
-rw-r--r--lib/public/Files/SimpleFS/InMemoryFile.php24
7 files changed, 55 insertions, 103 deletions
diff --git a/lib/private/Files/SimpleFS/NewSimpleFile.php b/lib/private/Files/SimpleFS/NewSimpleFile.php
index 76fc69ebbe7..5fdd794ba98 100644
--- a/lib/private/Files/SimpleFS/NewSimpleFile.php
+++ b/lib/private/Files/SimpleFS/NewSimpleFile.php
@@ -34,15 +34,12 @@ use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
class NewSimpleFile implements ISimpleFile {
- private $parentFolder;
- private $name;
- /** @var File|null */
- private $file = null;
+ private Folder $parentFolder;
+ private string $name;
+ private ?File $file = null;
/**
* File constructor.
- *
- * @param File $file
*/
public function __construct(Folder $parentFolder, string $name) {
$this->parentFolder = $parentFolder;
@@ -51,19 +48,15 @@ class NewSimpleFile implements ISimpleFile {
/**
* Get the name
- *
- * @return string
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
/**
* Get the size in bytes
- *
- * @return int
*/
- public function getSize() {
+ public function getSize(): int {
if ($this->file) {
return $this->file->getSize();
} else {
@@ -73,10 +66,8 @@ class NewSimpleFile implements ISimpleFile {
/**
* Get the ETag
- *
- * @return string
*/
- public function getETag() {
+ public function getETag(): string {
if ($this->file) {
return $this->file->getEtag();
} else {
@@ -86,10 +77,8 @@ class NewSimpleFile implements ISimpleFile {
/**
* Get the last modification time
- *
- * @return int
*/
- public function getMTime() {
+ public function getMTime(): int {
if ($this->file) {
return $this->file->getMTime();
} else {
@@ -100,11 +89,10 @@ class NewSimpleFile implements ISimpleFile {
/**
* Get the content
*
- * @return string
* @throws NotFoundException
* @throws NotPermittedException
*/
- public function getContent() {
+ public function getContent(): string {
if ($this->file) {
$result = $this->file->getContent();
@@ -125,7 +113,7 @@ class NewSimpleFile implements ISimpleFile {
* @throws NotPermittedException
* @throws NotFoundException
*/
- public function putContent($data) {
+ public function putContent($data): void {
try {
if ($this->file) {
$this->file->putContent($data);
@@ -147,7 +135,7 @@ class NewSimpleFile implements ISimpleFile {
*
* @throws NotFoundException
*/
- private function checkFile() {
+ private function checkFile(): void {
$cur = $this->file;
while ($cur->stat() === false) {
@@ -171,7 +159,7 @@ class NewSimpleFile implements ISimpleFile {
*
* @throws NotPermittedException
*/
- public function delete() {
+ public function delete(): void {
if ($this->file) {
$this->file->delete();
}
@@ -182,7 +170,7 @@ class NewSimpleFile implements ISimpleFile {
*
* @return string
*/
- public function getMimeType() {
+ public function getMimeType(): string {
if ($this->file) {
return $this->file->getMimeType();
} else {
diff --git a/lib/private/Files/SimpleFS/SimpleFile.php b/lib/private/Files/SimpleFS/SimpleFile.php
index 21a2fd92dcb..a07871337a6 100644
--- a/lib/private/Files/SimpleFS/SimpleFile.php
+++ b/lib/private/Files/SimpleFS/SimpleFile.php
@@ -30,52 +30,37 @@ use OCP\Files\NotPermittedException;
use OCP\Files\SimpleFS\ISimpleFile;
class SimpleFile implements ISimpleFile {
+ private File $file;
- /** @var File $file */
- private $file;
-
- /**
- * File constructor.
- *
- * @param File $file
- */
public function __construct(File $file) {
$this->file = $file;
}
/**
* Get the name
- *
- * @return string
*/
- public function getName() {
+ public function getName(): string {
return $this->file->getName();
}
/**
* Get the size in bytes
- *
- * @return int
*/
- public function getSize() {
+ public function getSize(): int {
return $this->file->getSize();
}
/**
* Get the ETag
- *
- * @return string
*/
- public function getETag() {
+ public function getETag(): string {
return $this->file->getEtag();
}
/**
* Get the last modification time
- *
- * @return int
*/
- public function getMTime() {
+ public function getMTime(): int {
return $this->file->getMTime();
}
@@ -84,9 +69,8 @@ class SimpleFile implements ISimpleFile {
*
* @throws NotPermittedException
* @throws NotFoundException
- * @return string
*/
- public function getContent() {
+ public function getContent(): string {
$result = $this->file->getContent();
if ($result === false) {
@@ -103,9 +87,9 @@ class SimpleFile implements ISimpleFile {
* @throws NotPermittedException
* @throws NotFoundException
*/
- public function putContent($data) {
+ public function putContent($data): void {
try {
- return $this->file->putContent($data);
+ $this->file->putContent($data);
} catch (NotFoundException $e) {
$this->checkFile();
}
@@ -121,7 +105,7 @@ class SimpleFile implements ISimpleFile {
*
* @throws NotFoundException
*/
- private function checkFile() {
+ private function checkFile(): void {
$cur = $this->file;
while ($cur->stat() === false) {
@@ -145,16 +129,14 @@ class SimpleFile implements ISimpleFile {
*
* @throws NotPermittedException
*/
- public function delete() {
+ public function delete(): void {
$this->file->delete();
}
/**
* Get the MimeType
- *
- * @return string
*/
- public function getMimeType() {
+ public function getMimeType(): string {
return $this->file->getMimeType();
}
@@ -179,7 +161,7 @@ class SimpleFile implements ISimpleFile {
/**
* Open the file as stream for writing, resulting resource can be operated as stream like the result from php's own fopen
*
- * @return resource
+ * @return resource|false
* @throws \OCP\Files\NotPermittedException
* @since 14.0.0
*/
diff --git a/lib/private/Files/SimpleFS/SimpleFolder.php b/lib/private/Files/SimpleFS/SimpleFolder.php
index cd2a712019e..263c25a8873 100644
--- a/lib/private/Files/SimpleFS/SimpleFolder.php
+++ b/lib/private/Files/SimpleFS/SimpleFolder.php
@@ -29,6 +29,7 @@ use OCP\Files\Folder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder;
+use OCP\Files\SimpleFS\ISimpleFile;
class SimpleFolder implements ISimpleFolder {
@@ -44,11 +45,11 @@ class SimpleFolder implements ISimpleFolder {
$this->folder = $folder;
}
- public function getName() {
+ public function getName(): string {
return $this->folder->getName();
}
- public function getDirectoryListing() {
+ public function getDirectoryListing(): array {
$listing = $this->folder->getDirectoryListing();
$fileListing = array_map(function (Node $file) {
@@ -63,15 +64,15 @@ class SimpleFolder implements ISimpleFolder {
return array_values($fileListing);
}
- public function delete() {
+ public function delete(): void {
$this->folder->delete();
}
- public function fileExists($name) {
+ public function fileExists(string $name): bool {
return $this->folder->nodeExists($name);
}
- public function getFile($name) {
+ public function getFile(string $name): ISimpleFile {
$file = $this->folder->get($name);
if (!($file instanceof File)) {
@@ -81,7 +82,7 @@ class SimpleFolder implements ISimpleFolder {
return new SimpleFile($file);
}
- public function newFile($name, $content = null) {
+ public function newFile(string $name, $content = null): ISimpleFile {
if ($content === null) {
// delay creating the file until it's written to
return new NewSimpleFile($this->folder, $name);
diff --git a/lib/public/Files/SimpleFS/ISimpleFile.php b/lib/public/Files/SimpleFS/ISimpleFile.php
index 8f1921cb7cb..34cd128d449 100644
--- a/lib/public/Files/SimpleFS/ISimpleFile.php
+++ b/lib/public/Files/SimpleFS/ISimpleFile.php
@@ -41,44 +41,39 @@ interface ISimpleFile {
/**
* Get the name
*
- * @return string
* @since 11.0.0
*/
- public function getName();
+ public function getName(): string;
/**
* Get the size in bytes
*
- * @return int
* @since 11.0.0
*/
- public function getSize();
+ public function getSize(): int;
/**
* Get the ETag
*
- * @return string
* @since 11.0.0
*/
- public function getETag();
+ public function getETag(): string;
/**
* Get the last modification time
*
- * @return int
* @since 11.0.0
*/
- public function getMTime();
+ public function getMTime(): int;
/**
* Get the content
*
* @throws NotPermittedException
* @throws NotFoundException
- * @return string
* @since 11.0.0
*/
- public function getContent();
+ public function getContent(): string;
/**
* Overwrite the file
@@ -88,7 +83,7 @@ interface ISimpleFile {
* @throws NotFoundException
* @since 11.0.0
*/
- public function putContent($data);
+ public function putContent($data): void;
/**
* Delete the file
@@ -96,15 +91,14 @@ interface ISimpleFile {
* @throws NotPermittedException
* @since 11.0.0
*/
- public function delete();
+ public function delete(): void;
/**
* Get the MimeType
*
- * @return string
* @since 11.0.0
*/
- public function getMimeType();
+ public function getMimeType(): string;
/**
* @since 24.0.0
diff --git a/lib/public/Files/SimpleFS/ISimpleFolder.php b/lib/public/Files/SimpleFS/ISimpleFolder.php
index 0159c41760b..3c8e6e88ab3 100644
--- a/lib/public/Files/SimpleFS/ISimpleFolder.php
+++ b/lib/public/Files/SimpleFS/ISimpleFolder.php
@@ -38,7 +38,7 @@ interface ISimpleFolder {
* @return ISimpleFile[]
* @since 11.0.0
*/
- public function getDirectoryListing();
+ public function getDirectoryListing(): array;
/**
* Check if a file with $name exists
@@ -47,28 +47,24 @@ interface ISimpleFolder {
* @return bool
* @since 11.0.0
*/
- public function fileExists($name);
+ public function fileExists(string $name): bool;
/**
* Get the file named $name from the folder
*
- * @param string $name
- * @return ISimpleFile
* @throws NotFoundException
* @since 11.0.0
*/
- public function getFile($name);
+ public function getFile(string $name): ISimpleFile;
/**
* Creates a new file with $name in the folder
*
- * @param string $name
* @param string|resource|null $content @since 19.0.0
- * @return ISimpleFile
* @throws NotPermittedException
* @since 11.0.0
*/
- public function newFile($name, $content = null);
+ public function newFile(string $name, $content = null): ISimpleFile;
/**
* Remove the folder and all the files in it
@@ -76,13 +72,12 @@ interface ISimpleFolder {
* @throws NotPermittedException
* @since 11.0.0
*/
- public function delete();
+ public function delete(): void;
/**
* Get the folder name
*
- * @return string
* @since 11.0.0
*/
- public function getName();
+ public function getName(): string;
}
diff --git a/lib/public/Files/SimpleFS/ISimpleRoot.php b/lib/public/Files/SimpleFS/ISimpleRoot.php
index fd590b66b31..31c3efe76dd 100644
--- a/lib/public/Files/SimpleFS/ISimpleRoot.php
+++ b/lib/public/Files/SimpleFS/ISimpleRoot.php
@@ -35,8 +35,6 @@ interface ISimpleRoot {
/**
* Get the folder with name $name
*
- * @param string $name
- * @return ISimpleFolder
* @throws NotFoundException
* @throws \RuntimeException
* @since 11.0.0
@@ -56,8 +54,6 @@ interface ISimpleRoot {
/**
* Create a new folder named $name
*
- * @param string $name
- * @return ISimpleFolder
* @throws NotPermittedException
* @throws \RuntimeException
* @since 11.0.0
diff --git a/lib/public/Files/SimpleFS/InMemoryFile.php b/lib/public/Files/SimpleFS/InMemoryFile.php
index 590cb43e1d6..393449d4f1f 100644
--- a/lib/public/Files/SimpleFS/InMemoryFile.php
+++ b/lib/public/Files/SimpleFS/InMemoryFile.php
@@ -36,17 +36,13 @@ use OCP\Files\NotPermittedException;
class InMemoryFile implements ISimpleFile {
/**
* Holds the file name.
- *
- * @var string
*/
- private $name;
+ private string $name;
/**
* Holds the file contents.
- *
- * @var string
*/
- private $contents;
+ private string $contents;
/**
* InMemoryFile constructor.
@@ -64,7 +60,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getName() {
+ public function getName(): string {
return $this->name;
}
@@ -72,7 +68,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getSize() {
+ public function getSize(): int {
return strlen($this->contents);
}
@@ -80,7 +76,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getETag() {
+ public function getETag(): string {
return '';
}
@@ -88,7 +84,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getMTime() {
+ public function getMTime(): int {
return time();
}
@@ -96,7 +92,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getContent() {
+ public function getContent(): string {
return $this->contents;
}
@@ -104,7 +100,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function putContent($data) {
+ public function putContent($data): void {
$this->contents = $data;
}
@@ -113,7 +109,7 @@ class InMemoryFile implements ISimpleFile {
*
* @since 16.0.0
*/
- public function delete() {
+ public function delete(): void {
// unimplemented for in memory files
}
@@ -121,7 +117,7 @@ class InMemoryFile implements ISimpleFile {
* @inheritdoc
* @since 16.0.0
*/
- public function getMimeType() {
+ public function getMimeType(): string {
$fileInfo = new \finfo(FILEINFO_MIME_TYPE);
return $fileInfo->buffer($this->contents);
}