Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 12 additions & 24 deletions lib/private/Files/SimpleFS/NewSimpleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,15 +34,12 @@
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;
Expand All @@ -51,19 +48,15 @@ public function __construct(Folder $parentFolder, string $name) {

/**
* 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 {
Expand All @@ -73,10 +66,8 @@ public function getSize() {

/**
* Get the ETag
*
* @return string
*/
public function getETag() {
public function getETag(): string {
if ($this->file) {
return $this->file->getEtag();
} else {
Expand All @@ -86,10 +77,8 @@ public function getETag() {

/**
* Get the last modification time
*
* @return int
*/
public function getMTime() {
public function getMTime(): int {
if ($this->file) {
return $this->file->getMTime();
} else {
Expand All @@ -100,11 +89,10 @@ public function getMTime() {
/**
* Get the content
*
* @return string
* @throws NotFoundException
* @throws NotPermittedException
*/
public function getContent() {
public function getContent(): string {
if ($this->file) {
$result = $this->file->getContent();

Expand All @@ -125,7 +113,7 @@ public function getContent() {
* @throws NotPermittedException
* @throws NotFoundException
*/
public function putContent($data) {
public function putContent($data): void {
try {
if ($this->file) {
$this->file->putContent($data);
Expand All @@ -147,7 +135,7 @@ public function putContent($data) {
*
* @throws NotFoundException
*/
private function checkFile() {
private function checkFile(): void {
$cur = $this->file;

while ($cur->stat() === false) {
Expand All @@ -171,7 +159,7 @@ private function checkFile() {
*
* @throws NotPermittedException
*/
public function delete() {
public function delete(): void {
if ($this->file) {
$this->file->delete();
}
Expand All @@ -182,7 +170,7 @@ public function delete() {
*
* @return string
*/
public function getMimeType() {
public function getMimeType(): string {
if ($this->file) {
return $this->file->getMimeType();
} else {
Expand Down
42 changes: 12 additions & 30 deletions lib/private/Files/SimpleFS/SimpleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,52 +30,37 @@
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();
}

Expand All @@ -84,9 +69,8 @@ public function getMTime() {
*
* @throws NotPermittedException
* @throws NotFoundException
* @return string
*/
public function getContent() {
public function getContent(): string {
$result = $this->file->getContent();

if ($result === false) {
Expand All @@ -103,9 +87,9 @@ public function getContent() {
* @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();
}
Expand All @@ -121,7 +105,7 @@ public function putContent($data) {
*
* @throws NotFoundException
*/
private function checkFile() {
private function checkFile(): void {
$cur = $this->file;

while ($cur->stat() === false) {
Expand All @@ -145,16 +129,14 @@ private function checkFile() {
*
* @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();
}

Expand All @@ -179,7 +161,7 @@ public function read() {
/**
* 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
*/
Expand Down
13 changes: 7 additions & 6 deletions lib/private/Files/SimpleFS/SimpleFolder.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\Files\SimpleFS\ISimpleFolder;
use OCP\Files\SimpleFS\ISimpleFile;

class SimpleFolder implements ISimpleFolder {

Expand All @@ -44,11 +45,11 @@ public function __construct(Folder $folder) {
$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) {
Expand All @@ -63,15 +64,15 @@ public function getDirectoryListing() {
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)) {
Expand All @@ -81,7 +82,7 @@ public function getFile($name) {
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);
Expand Down
22 changes: 8 additions & 14 deletions lib/public/Files/SimpleFS/ISimpleFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -88,23 +83,22 @@ public function getContent();
* @throws NotFoundException
* @since 11.0.0
*/
public function putContent($data);
public function putContent($data): void;

/**
* Delete the file
*
* @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
Expand Down
Loading