From 0f7fa06c4c341c5de13d1281774a8dd3654528c5 Mon Sep 17 00:00:00 2001 From: tinect Date: Sat, 3 Feb 2024 22:59:56 +0100 Subject: [PATCH] style: [InMemory] update method usages to PHP 8.0 --- src/InMemory/InMemoryFilesystemAdapter.php | 37 +++++++++++----------- 1 file changed, 18 insertions(+), 19 deletions(-) diff --git a/src/InMemory/InMemoryFilesystemAdapter.php b/src/InMemory/InMemoryFilesystemAdapter.php index 76de6ad9f..4d1182060 100644 --- a/src/InMemory/InMemoryFilesystemAdapter.php +++ b/src/InMemory/InMemoryFilesystemAdapter.php @@ -19,11 +19,10 @@ use function array_keys; use function rtrim; -use function strpos; class InMemoryFilesystemAdapter implements FilesystemAdapter { - const DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST = '______DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST'; + public const DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST = '______DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST'; /** * @var InMemoryFile[] @@ -85,14 +84,14 @@ public function delete(string $path): void unset($this->files[$this->preparePath($path)]); } - public function deleteDirectory(string $prefix): void + public function deleteDirectory(string $path): void { - $prefix = $this->preparePath($prefix); - $prefix = rtrim($prefix, '/') . '/'; + $path = $this->preparePath($path); + $path = rtrim($path, '/') . '/'; - foreach (array_keys($this->files) as $path) { - if (strpos($path, $prefix) === 0) { - unset($this->files[$path]); + foreach (array_keys($this->files) as $filePath) { + if (str_starts_with($filePath, $path)) { + unset($this->files[$filePath]); } } } @@ -105,11 +104,11 @@ public function createDirectory(string $path, Config $config): void public function directoryExists(string $path): bool { - $prefix = $this->preparePath($path); - $prefix = rtrim($prefix, '/') . '/'; + $path = $this->preparePath($path); + $path = rtrim($path, '/') . '/'; - foreach (array_keys($this->files) as $path) { - if (strpos($path, $prefix) === 0) { + foreach (array_keys($this->files) as $filePath) { + if (str_starts_with($filePath, $path)) { return true; } } @@ -184,9 +183,9 @@ public function listContents(string $path, bool $deep): iterable $prefixLength = strlen($prefix); $listedDirectories = []; - foreach ($this->files as $path => $file) { - if (substr($path, 0, $prefixLength) === $prefix) { - $subPath = substr($path, $prefixLength); + foreach ($this->files as $filePath => $file) { + if (str_starts_with($filePath, $prefix)) { + $subPath = substr($filePath, $prefixLength); $dirname = dirname($subPath); if ($dirname !== '.') { @@ -200,7 +199,7 @@ public function listContents(string $path, bool $deep): iterable $dirPath .= $part . '/'; - if ( ! in_array($dirPath, $listedDirectories)) { + if ( ! in_array($dirPath, $listedDirectories, true)) { $listedDirectories[] = $dirPath; yield new DirectoryAttributes(trim($prefix . $dirPath, '/')); } @@ -208,12 +207,12 @@ public function listContents(string $path, bool $deep): iterable } $dummyFilename = self::DUMMY_FILE_FOR_FORCED_LISTING_IN_FLYSYSTEM_TEST; - if (substr($path, -strlen($dummyFilename)) === $dummyFilename) { + if (str_ends_with($filePath, $dummyFilename)) { continue; } - if ($deep === true || strpos($subPath, '/') === false) { - yield new FileAttributes(ltrim($path, '/'), $file->fileSize(), $file->visibility(), $file->lastModified(), $file->mimeType()); + if ($deep === true || ! str_contains($subPath, '/')) { + yield new FileAttributes(ltrim($filePath, '/'), $file->fileSize(), $file->visibility(), $file->lastModified(), $file->mimeType()); } } }