Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

style: [InMemory] update method usages to PHP 8.0 #1749

Merged
merged 1 commit into from
Feb 4, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 18 additions & 19 deletions src/InMemory/InMemoryFilesystemAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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[]
Expand Down Expand Up @@ -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]);
}
}
}
Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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 !== '.') {
Expand All @@ -200,20 +199,20 @@ 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, '/'));
}
}
}

$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());
}
}
}
Expand Down
Loading