Skip to content

Commit

Permalink
Filesystem 5.0.0
Browse files Browse the repository at this point in the history
  • Loading branch information
Awilum committed Jul 3, 2022
1 parent 6f9e752 commit 79c571b
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 15 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
<a name="5.0.0"></a>
# [5.0.0](https://github.com/glowyphp/filesystem) (2022-07-03)
* All Helpers functions are placed into the Glowy/Filesystem namespace.
* Use union types.

<a name="4.0.0"></a>
# [4.0.0](https://github.com/glowyphp/filesystem) (2021-07-02)
* Moving to PHP 8.1
Expand Down
8 changes: 4 additions & 4 deletions src/Directory.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Directory
*
* Current directory path.
*/
public ?string $path = null;
public string|null $path = null;

/**
* Constructor
Expand Down Expand Up @@ -113,7 +113,7 @@ public function move(string $destination): bool
*
* @return bool Returns TRUE on success or FALSE on failure.
*/
public function copy(string $destination, ?int $flags = null): bool
public function copy(string $destination, int|null $flags = null): bool
{
$directory = $this->path;

Expand Down Expand Up @@ -216,7 +216,7 @@ public function isDirectory(): bool
*
* @return string|null Current path
*/
public function path(): ?string
public function path(): string|null
{
return $this->path;
}
Expand All @@ -230,7 +230,7 @@ public function path(): ?string
*
* @return mixed
*/
public function chmod(?int $mode = null)
public function chmod(int|null $mode = null)
{
if ($mode) {
return chmod($this->path, $mode);
Expand Down
20 changes: 10 additions & 10 deletions src/File.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ class File
*
* Current file absolute path
*/
public ?string $path = null;
public string|null $path = null;

/**
* Constructor
Expand All @@ -62,7 +62,7 @@ public function __construct(string $path)
*
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
*/
public function put(string $data, bool $lock = false)
public function put(string $data, bool $lock = false): int|bool
{
return file_put_contents($this->path, $data, $lock ? LOCK_EX : 0);
}
Expand All @@ -72,9 +72,9 @@ public function put(string $data, bool $lock = false)
*
* @param bool $lock Acquire an exclusive lock on the file while proceeding to the reading.
*
* @return string|false The file contents or false on failure.
* @return string|bool The file contents or false on failure.
*/
public function get($lock = false)
public function get($lock = false): string|bool
{
if ($this->isFile($this->path)) {
$contents = $lock ? $this->sharedGet() : file_get_contents($this->path);
Expand All @@ -90,9 +90,9 @@ public function get($lock = false)
/**
* Get contents of a file with shared access.
*
* @return string|false The file contents or false on failure.
* @return string|bool The file contents or false on failure.
*/
public function sharedGet()
public function sharedGet(): string|bool
{
$contents = false;

Expand Down Expand Up @@ -142,7 +142,7 @@ public function isEqual(string $file): bool
*
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
*/
public function prepend(string $data)
public function prepend(string $data): int|bool
{
if ($this->exists($this->path)) {
return $this->put($data . $this->get($this->path));
Expand All @@ -158,7 +158,7 @@ public function prepend(string $data)
*
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
*/
public function append(string $data)
public function append(string $data): int|bool
{
return file_put_contents($this->path, $data, FILE_APPEND);
}
Expand Down Expand Up @@ -287,7 +287,7 @@ public function name(): string
*
* @return string|null Current path
*/
public function path(): ?string
public function path(): string|null
{
return $this->path;
}
Expand Down Expand Up @@ -387,7 +387,7 @@ public function isFile(): bool
*
* @return mixed
*/
public function chmod(?int $mode = null)
public function chmod(int|null $mode = null)
{
if ($mode) {
return chmod($this->path, $mode);
Expand Down
4 changes: 3 additions & 1 deletion src/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,15 @@

declare(strict_types=1);

namespace Glowy\Filesystem;

use Glowy\Filesystem\Filesystem;

if (! function_exists('filesystem')) {
/**
* Create a Filesystem instance.
*/
function filesystem(): Filesystem
function filesystem(): \Glowy\Filesystem\Filesystem
{
return new Filesystem();
}
Expand Down
2 changes: 2 additions & 0 deletions tests/FilesystemTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
use Glowy\Filesystem\File;
use Glowy\Filesystem\Directory;

use function Glowy\Filesystem\filesystem;

beforeEach(function (): void {
$this->tempDir = __DIR__ . '/tmp';
@mkdir($this->tempDir);
Expand Down

0 comments on commit 79c571b

Please sign in to comment.