Skip to content

Commit

Permalink
General code improvements.
Browse files Browse the repository at this point in the history
  • Loading branch information
vinogradsoft committed Nov 26, 2023
1 parent c651889 commit 1fa87fb
Show file tree
Hide file tree
Showing 15 changed files with 159 additions and 95 deletions.
28 changes: 23 additions & 5 deletions src/AbstractDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ abstract class AbstractDirectory extends NestedObject
protected const ALREADY_EXISTS_MESSAGE = 'A directory or file named "%s" already exists.';

/**@var AbstractDirectory[] */
protected $directories = [];
protected array $directories = [];

/**@var AbstractFile[] */
protected $files = [];
protected array $files = [];

/**
* @return AbstractDirectory[]
Expand Down Expand Up @@ -85,8 +85,10 @@ protected function isOneOfTheParents(?AbstractDirectory $parent = null, Abstract

/**
* @param AbstractDirectory $directory
* @return void
* @throws TreeException
*/
public function removeDirectory(AbstractDirectory $directory)
public function removeDirectory(AbstractDirectory $directory): void
{
$name = $directory->getLocalName();
if (!array_key_exists($name, $this->directories)) {
Expand All @@ -99,6 +101,7 @@ public function removeDirectory(AbstractDirectory $directory)
/**
* @param string $name
* @return AbstractDirectory
* @throws NotFoundException
*/
public function getDirectoryBy(string $name): AbstractDirectory
{
Expand All @@ -108,6 +111,10 @@ public function getDirectoryBy(string $name): AbstractDirectory
return $this->directories[$name];
}

/**
* @return void
* @throws TreeException
*/
public function removeFromParent(): void
{
if (empty($this->parent)) {
Expand Down Expand Up @@ -141,7 +148,11 @@ public function getFiles(): array
return $this->files;
}


/**
* @param string $name
* @return AbstractFile
* @throws NotFoundException
*/
public function getFileBy(string $name): AbstractFile
{
if (!array_key_exists($name, $this->files)) {
Expand All @@ -152,6 +163,8 @@ public function getFileBy(string $name): AbstractFile

/**
* @param AbstractFile $file
* @return void
* @throws AlreadyExistException
*/
public function addFile(AbstractFile $file): void
{
Expand All @@ -169,8 +182,10 @@ public function addFile(AbstractFile $file): void

/**
* @param AbstractFile $file
* @return void
* @throws TreeException
*/
public function removeFile(AbstractFile $file)
public function removeFile(AbstractFile $file): void
{
$name = $file->getLocalName();
if (!array_key_exists($name, $this->files)) {
Expand All @@ -182,6 +197,7 @@ public function removeFile(AbstractFile $file)

/**
* @param string|null $name
* @throws TreeException
*/
public function setLocalName(?string $name = null): void
{
Expand All @@ -201,6 +217,7 @@ public function setLocalName(?string $name = null): void

/**
* @param string $oldName
* @return void
* @throws TreeException
*/
public function updateDirectoryName(string $oldName): void
Expand All @@ -225,6 +242,7 @@ public function updateDirectoryName(string $oldName): void

/**
* @param string $oldName
* @return void
* @throws TreeException
*/
public function updateFileName(string $oldName): void
Expand Down
12 changes: 7 additions & 5 deletions src/AbstractFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@

abstract class AbstractFile extends NestedObject
{

/**
*
* @return void
*/
public function removeFromParent(): void
{
Expand Down Expand Up @@ -45,12 +46,12 @@ public function isChild(): bool
}

/**
*
* @return void
*/
abstract public function write(): void;

/**
*
* @return void
*/
public function delete(): void
{
Expand All @@ -59,7 +60,7 @@ public function delete(): void
}

/**
*
* @return void
*/
abstract protected function removeSelf(): void;

Expand All @@ -75,7 +76,7 @@ public function getExtension(): string
* @param string $name
* @return false|string
*/
private function getExtensionImpl(string $name)
private function getExtensionImpl(string $name): false|string
{
$n = strrpos($name, ".");
return ($n === false) ? "" : substr($name, $n + 1);
Expand All @@ -88,4 +89,5 @@ public function getSourceExtension(): string
{
return $this->getExtensionImpl((string)$this->pathObject->getLast());
}

}
2 changes: 2 additions & 0 deletions src/AbstractFilesystemFunctionality.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

abstract class AbstractFilesystemFunctionality extends AbstractFunctionality
{

/**
* @param SupportedFunctionalities $component
* @param string $methodName
Expand All @@ -25,4 +26,5 @@ protected function revokeMethod(SupportedFunctionalities $component, string $met
{
FileFunctionalitiesContext::getFunctionalitySupport($component)->uninstallMethod($methodName);
}

}
19 changes: 10 additions & 9 deletions src/AbstractFilesystemObject.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,15 +12,15 @@ abstract class AbstractFilesystemObject implements SupportedFunctionalities
/**
* @param Functionality $functionality
*/
protected function addFunctionality(Functionality $functionality)
protected function addFunctionality(Functionality $functionality): void
{
$functionality->install($this);
}

/**
* @param Functionality $functionality
*/
protected function removeFunctionality(Functionality $functionality)
protected function removeFunctionality(Functionality $functionality): void
{
$functionality->uninstall($this);
}
Expand All @@ -30,13 +30,13 @@ protected function removeFunctionality(Functionality $functionality)
* @param $args
* @return mixed
*/
public function __call($method, $args)
public function __call($method, $args): mixed
{
return FileFunctionalitiesContext::getFunctionalitySupport($this)->fireCallMethodEvent($this, $method, $args);
}

/**
*
* @return void
*/
public function revokeAllSupports(): void
{
Expand All @@ -53,15 +53,16 @@ public function equals(AbstractFilesystemObject $filesystemObject): bool
}

/**
* @param $data
* @param mixed $data
* @return void
*/
abstract protected function setData($data): void;
abstract protected function setData(mixed $data): void;

/**
* @param $data
* @return AbstractFilesystemObject
* @param mixed $data
* @return $this
*/
public function cloneWithData($data): AbstractFilesystemObject
public function cloneWithData(mixed $data): AbstractFilesystemObject
{
$support = FileFunctionalitiesContext::getFunctionalitySupport($this);
$copyStorage = $support->copyStorage();
Expand Down
2 changes: 2 additions & 0 deletions src/DefaultFilesystem.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@

class DefaultFilesystem implements FileSystem
{

/**
* @param string $path
* @return string
Expand Down Expand Up @@ -138,4 +139,5 @@ public function yamlParseFile($filename, $pos = 0, &$ndocs = null, array $callba
}
return $result;
}

}
21 changes: 15 additions & 6 deletions src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
class Directory extends AbstractDirectory
{

/** @var bool */
protected $synchronized = false;
protected bool $synchronized = false;

/**
* @param string $name
Expand Down Expand Up @@ -152,7 +151,7 @@ public function getSourcePath(): string
}

/**
*
* @return void
*/
public function delete(): void
{
Expand All @@ -163,6 +162,9 @@ public function delete(): void
$this->removeAllDirectories();
}

/**
* @return void
*/
protected function removeAllDirectories(): void
{
if (!empty($this->parent)) {
Expand All @@ -178,7 +180,7 @@ protected function removeAllDirectories(): void
/**
* @param string $path
*/
public function move(string $path)
public function move(string $path): void
{
$deletePaths = $this->getPathsAllDirectories();
$this->moveAll($path);
Expand Down Expand Up @@ -220,6 +222,9 @@ protected function moveAll(string $path): void
}
}

/**
* @return void
*/
protected function deleteAllFiles(): void
{
/** @var File $file */
Expand Down Expand Up @@ -288,7 +293,10 @@ protected function getFilesPaths(): array
return $result;
}

protected function initBindWithFilesystem()
/**
* @return void
*/
protected function initBindWithFilesystem(): void
{
FileFunctionalitiesContext::getFunctionalitySupport($this)
->fireCallMethodEvent($this, 'assertInitBind', [
Expand All @@ -314,7 +322,7 @@ protected function setBindedFlag(bool $value): void
}

/**
*
* @return void
*/
public function revokeAllSupports(): void
{
Expand All @@ -325,4 +333,5 @@ public function revokeAllSupports(): void
$this->pathObject = null;
$this->synchronized = false;
}

}
Loading

0 comments on commit 1fa87fb

Please sign in to comment.