Skip to content

Commit 79c571b

Browse files
committed
Filesystem 5.0.0
1 parent 6f9e752 commit 79c571b

File tree

5 files changed

+24
-15
lines changed

5 files changed

+24
-15
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
<a name="5.0.0"></a>
2+
# [5.0.0](https://github.com/glowyphp/filesystem) (2022-07-03)
3+
* All Helpers functions are placed into the Glowy/Filesystem namespace.
4+
* Use union types.
5+
16
<a name="4.0.0"></a>
27
# [4.0.0](https://github.com/glowyphp/filesystem) (2021-07-02)
38
* Moving to PHP 8.1

src/Directory.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Directory
2525
*
2626
* Current directory path.
2727
*/
28-
public ?string $path = null;
28+
public string|null $path = null;
2929

3030
/**
3131
* Constructor
@@ -113,7 +113,7 @@ public function move(string $destination): bool
113113
*
114114
* @return bool Returns TRUE on success or FALSE on failure.
115115
*/
116-
public function copy(string $destination, ?int $flags = null): bool
116+
public function copy(string $destination, int|null $flags = null): bool
117117
{
118118
$directory = $this->path;
119119

@@ -216,7 +216,7 @@ public function isDirectory(): bool
216216
*
217217
* @return string|null Current path
218218
*/
219-
public function path(): ?string
219+
public function path(): string|null
220220
{
221221
return $this->path;
222222
}
@@ -230,7 +230,7 @@ public function path(): ?string
230230
*
231231
* @return mixed
232232
*/
233-
public function chmod(?int $mode = null)
233+
public function chmod(int|null $mode = null)
234234
{
235235
if ($mode) {
236236
return chmod($this->path, $mode);

src/File.php

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class File
4242
*
4343
* Current file absolute path
4444
*/
45-
public ?string $path = null;
45+
public string|null $path = null;
4646

4747
/**
4848
* Constructor
@@ -62,7 +62,7 @@ public function __construct(string $path)
6262
*
6363
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
6464
*/
65-
public function put(string $data, bool $lock = false)
65+
public function put(string $data, bool $lock = false): int|bool
6666
{
6767
return file_put_contents($this->path, $data, $lock ? LOCK_EX : 0);
6868
}
@@ -72,9 +72,9 @@ public function put(string $data, bool $lock = false)
7272
*
7373
* @param bool $lock Acquire an exclusive lock on the file while proceeding to the reading.
7474
*
75-
* @return string|false The file contents or false on failure.
75+
* @return string|bool The file contents or false on failure.
7676
*/
77-
public function get($lock = false)
77+
public function get($lock = false): string|bool
7878
{
7979
if ($this->isFile($this->path)) {
8080
$contents = $lock ? $this->sharedGet() : file_get_contents($this->path);
@@ -90,9 +90,9 @@ public function get($lock = false)
9090
/**
9191
* Get contents of a file with shared access.
9292
*
93-
* @return string|false The file contents or false on failure.
93+
* @return string|bool The file contents or false on failure.
9494
*/
95-
public function sharedGet()
95+
public function sharedGet(): string|bool
9696
{
9797
$contents = false;
9898

@@ -142,7 +142,7 @@ public function isEqual(string $file): bool
142142
*
143143
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
144144
*/
145-
public function prepend(string $data)
145+
public function prepend(string $data): int|bool
146146
{
147147
if ($this->exists($this->path)) {
148148
return $this->put($data . $this->get($this->path));
@@ -158,7 +158,7 @@ public function prepend(string $data)
158158
*
159159
* @return int|bool Returns the number of bytes that were written to the file, or FALSE on failure.
160160
*/
161-
public function append(string $data)
161+
public function append(string $data): int|bool
162162
{
163163
return file_put_contents($this->path, $data, FILE_APPEND);
164164
}
@@ -287,7 +287,7 @@ public function name(): string
287287
*
288288
* @return string|null Current path
289289
*/
290-
public function path(): ?string
290+
public function path(): string|null
291291
{
292292
return $this->path;
293293
}
@@ -387,7 +387,7 @@ public function isFile(): bool
387387
*
388388
* @return mixed
389389
*/
390-
public function chmod(?int $mode = null)
390+
public function chmod(int|null $mode = null)
391391
{
392392
if ($mode) {
393393
return chmod($this->path, $mode);

src/helpers.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,13 +2,15 @@
22

33
declare(strict_types=1);
44

5+
namespace Glowy\Filesystem;
6+
57
use Glowy\Filesystem\Filesystem;
68

79
if (! function_exists('filesystem')) {
810
/**
911
* Create a Filesystem instance.
1012
*/
11-
function filesystem(): Filesystem
13+
function filesystem(): \Glowy\Filesystem\Filesystem
1214
{
1315
return new Filesystem();
1416
}

tests/FilesystemTest.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
use Glowy\Filesystem\File;
77
use Glowy\Filesystem\Directory;
88

9+
use function Glowy\Filesystem\filesystem;
10+
911
beforeEach(function (): void {
1012
$this->tempDir = __DIR__ . '/tmp';
1113
@mkdir($this->tempDir);

0 commit comments

Comments
 (0)