aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Files/SimpleFS/NewSimpleFile.php
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Files/SimpleFS/NewSimpleFile.php')
-rw-r--r--lib/private/Files/SimpleFS/NewSimpleFile.php78
1 files changed, 31 insertions, 47 deletions
diff --git a/lib/private/Files/SimpleFS/NewSimpleFile.php b/lib/private/Files/SimpleFS/NewSimpleFile.php
index 381948a7440..d0986592c03 100644
--- a/lib/private/Files/SimpleFS/NewSimpleFile.php
+++ b/lib/private/Files/SimpleFS/NewSimpleFile.php
@@ -3,28 +3,9 @@
declare(strict_types=1);
/**
- * @copyright Copyright (c) 2020 Robin Appelman <robin@icewind.nl>
- *
- * @author Christoph Wurst <christoph@winzerhof-wurst.at>
- * @author Robin Appelman <robin@icewind.nl>
- *
- * @license GNU AGPL version 3 or any later version
- *
- * This program is free software: you can redistribute it and/or modify
- * it under the terms of the GNU Affero General Public License as
- * published by the Free Software Foundation, either version 3 of the
- * License, or (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Affero General Public License for more details.
- *
- * You should have received a copy of the GNU Affero General Public License
- * along with this program. If not, see <http://www.gnu.org/licenses/>.
- *
+ * SPDX-FileCopyrightText: 2020 Nextcloud GmbH and Nextcloud contributors
+ * SPDX-License-Identifier: AGPL-3.0-or-later
*/
-
namespace OC\Files\SimpleFS;
use Icewind\Streams\CallbackWrapper;
@@ -35,15 +16,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;
@@ -52,19 +30,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|float {
if ($this->file) {
return $this->file->getSize();
} else {
@@ -74,10 +48,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 {
@@ -87,10 +59,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 {
@@ -101,11 +71,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();
@@ -126,7 +95,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);
@@ -140,7 +109,7 @@ class NewSimpleFile implements ISimpleFile {
/**
* Sometimes there are some issues with the AppData. Most of them are from
- * user error. But we should handle them gracefull anyway.
+ * user error. But we should handle them gracefully anyway.
*
* If for some reason the current file can't be found. We remove it.
* Then traverse up and check all folders if they exists. This so that the
@@ -148,7 +117,11 @@ class NewSimpleFile implements ISimpleFile {
*
* @throws NotFoundException
*/
- private function checkFile() {
+ private function checkFile(): void {
+ if (!$this->file) {
+ throw new NotFoundException('File not set');
+ }
+
$cur = $this->file;
while ($cur->stat() === false) {
@@ -172,7 +145,7 @@ class NewSimpleFile implements ISimpleFile {
*
* @throws NotPermittedException
*/
- public function delete() {
+ public function delete(): void {
if ($this->file) {
$this->file->delete();
}
@@ -183,7 +156,7 @@ class NewSimpleFile implements ISimpleFile {
*
* @return string
*/
- public function getMimeType() {
+ public function getMimeType(): string {
if ($this->file) {
return $this->file->getMimeType();
} else {
@@ -192,9 +165,20 @@ class NewSimpleFile implements ISimpleFile {
}
/**
+ * {@inheritDoc}
+ */
+ public function getExtension(): string {
+ if ($this->file) {
+ return $this->file->getExtension();
+ } else {
+ return \pathinfo($this->name, PATHINFO_EXTENSION);
+ }
+ }
+
+ /**
* Open the file as stream for reading, 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
*/