From c9b723444d45c006b68485e3a77096d4b4f914e6 Mon Sep 17 00:00:00 2001 From: Abdul Malik Ikhsan Date: Sun, 3 Nov 2024 15:28:50 +0700 Subject: [PATCH] Update to use PHP 8.1 syntax Signed-off-by: Abdul Malik Ikhsan --- src/Filesystem.php | 4 +-- .../Exception/MetadataException.php | 2 +- src/Filesystem/Exception/UnlinkException.php | 2 +- src/FilesystemIterator.php | 33 +++++++++---------- test/unit/FilesystemOptionsTest.php | 5 +-- 5 files changed, 22 insertions(+), 24 deletions(-) diff --git a/src/Filesystem.php b/src/Filesystem.php index 1a01714..a6ec32e 100644 --- a/src/Filesystem.php +++ b/src/Filesystem.php @@ -104,8 +104,8 @@ final class Filesystem extends AbstractMetadataCapableAdapter implements */ private string $lastFileSpec = ''; - private FilesystemInteractionInterface $filesystem; - private ClockInterface $clock; + private readonly FilesystemInteractionInterface $filesystem; + private readonly ClockInterface $clock; /** * @param null|iterable|FilesystemOptions $options diff --git a/src/Filesystem/Exception/MetadataException.php b/src/Filesystem/Exception/MetadataException.php index a20c6af..7d4dfac 100644 --- a/src/Filesystem/Exception/MetadataException.php +++ b/src/Filesystem/Exception/MetadataException.php @@ -16,7 +16,7 @@ final class MetadataException extends RuntimeException public const METADATA_MTIME = 'mtime'; public const METADATA_FILESIZE = 'filesize'; - private ErrorException $error; + private readonly ErrorException $error; /** * @psalm-param MetadataException::METADATA_* $metadata diff --git a/src/Filesystem/Exception/UnlinkException.php b/src/Filesystem/Exception/UnlinkException.php index cc228fd..3ea8a41 100644 --- a/src/Filesystem/Exception/UnlinkException.php +++ b/src/Filesystem/Exception/UnlinkException.php @@ -11,7 +11,7 @@ final class UnlinkException extends RuntimeException { - private ErrorException $error; + private readonly ErrorException $error; public function __construct(string $path, ErrorException $error) { diff --git a/src/FilesystemIterator.php b/src/FilesystemIterator.php index f2fa16e..1451112 100644 --- a/src/FilesystemIterator.php +++ b/src/FilesystemIterator.php @@ -16,11 +16,6 @@ */ final class FilesystemIterator implements IteratorInterface { - /** - * The Filesystem storage instance - */ - private Filesystem $storage; - /** * The iterator mode * @@ -31,24 +26,26 @@ final class FilesystemIterator implements IteratorInterface /** * The GlobIterator instance */ - private GlobIterator $globIterator; - - /** - * The namespace sprefix - */ - private string $prefix; + private readonly GlobIterator $globIterator; /** * String length of namespace prefix */ - private int $prefixLength; - - public function __construct(Filesystem $storage, string $path, string $prefix) - { - $this->storage = $storage; + private readonly int $prefixLength; + + public function __construct( + /** + * The Filesystem storage instance + */ + private readonly Filesystem $storage, + string $path, + /** + * The namespace sprefix + */ + private readonly string $prefix + ) { $this->globIterator = new GlobIterator($path, GlobIterator::KEY_AS_FILENAME); - $this->prefix = $prefix; - $this->prefixLength = strlen($prefix); + $this->prefixLength = strlen($this->prefix); } /** diff --git a/test/unit/FilesystemOptionsTest.php b/test/unit/FilesystemOptionsTest.php index 6bc3fcc..f9fc1d8 100644 --- a/test/unit/FilesystemOptionsTest.php +++ b/test/unit/FilesystemOptionsTest.php @@ -21,6 +21,7 @@ use function realpath; use function rmdir; use function str_replace; +use function str_starts_with; use function strpos; use function substr; use function sys_get_temp_dir; @@ -99,7 +100,7 @@ public function testNormalizeCacheDir(): void public function testSetCacheDirNotWritableException(): void { - if (substr(PHP_OS, 0, 3) === 'WIN') { + if (str_starts_with(PHP_OS, 'WIN')) { self::markTestSkipped('Not testable on windows'); } else { $out = []; @@ -131,7 +132,7 @@ public function testSetCacheDirNotWritableException(): void public function testSetCacheDirNotReadableException(): void { - if (substr(PHP_OS, 0, 3) === 'WIN') { + if (str_starts_with(PHP_OS, 'WIN')) { self::markTestSkipped('Not testable on windows'); } else { @exec('whoami 2>&1', $out, $ret);