From 9cf97ffcabe9bab158454c12a4dd27f5216cba9d Mon Sep 17 00:00:00 2001 From: tinect Date: Sat, 3 Feb 2024 23:01:53 +0100 Subject: [PATCH 1/2] fix: [FTP] ensure prefixer in method directoryExists --- src/Ftp/FtpAdapter.php | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 079dd010a..7b298cb2a 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -634,9 +634,10 @@ private function hasFtpConnection(): bool public function directoryExists(string $path): bool { + $location = $this->prefixer()->prefixPath($path); $connection = $this->connection(); - return @ftp_chdir($connection, $path) === true; + return @ftp_chdir($connection, $location) === true; } /** From 67086c1f1c76c9f355df6cae3d4cae2f06f979f7 Mon Sep 17 00:00:00 2001 From: tinect Date: Sat, 3 Feb 2024 23:17:16 +0100 Subject: [PATCH 2/2] style: [FTP] update method usages to PHP 8.0 --- src/Ftp/FtpAdapter.php | 18 ++++-------------- 1 file changed, 4 insertions(+), 14 deletions(-) diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 7b298cb2a..2f0e6dc8e 100644 --- a/src/Ftp/FtpAdapter.php +++ b/src/Ftp/FtpAdapter.php @@ -275,7 +275,7 @@ private function fetchMetadata(string $path, string $type): FileAttributes $object = @ftp_raw($this->connection(), 'STAT ' . $location); - if (empty($object) || count($object) < 3 || substr($object[1], 0, 5) === "ftpd:") { + if (empty($object) || count($object) < 3 || str_starts_with($object[1], "ftpd:")) { throw UnableToRetrieveMetadata::create($path, $type, error_get_last()['message'] ?? ''); } @@ -450,7 +450,7 @@ private function normalizeUnixObject(string $item, string $base): StorageAttribu private function listingItemIsDirectory(string $permissions): bool { - return substr($permissions, 0, 1) === 'd'; + return str_starts_with($permissions, 'd'); } private function normalizeUnixTimestamp(string $month, string $day, string $timeOrYear): int @@ -459,14 +459,12 @@ private function normalizeUnixTimestamp(string $month, string $day, string $time $year = $timeOrYear; $hour = '00'; $minute = '00'; - $seconds = '00'; } else { $year = date('Y'); [$hour, $minute] = explode(':', $timeOrYear); - $seconds = '00'; } - $dateTime = DateTime::createFromFormat('Y-M-j-G:i:s', "{$year}-{$month}-{$day}-{$hour}:{$minute}:{$seconds}"); + $dateTime = DateTime::createFromFormat('Y-M-j-G:i:s', "$year-$month-$day-$hour:$minute:00"); return $dateTime->getTimestamp(); } @@ -484,7 +482,7 @@ private function normalizePermissions(string $permissions): int $parts = str_split($permissions, 3); // convert the groups - $mapper = function ($part) { + $mapper = static function ($part) { return array_sum(str_split($part)); }; @@ -492,11 +490,6 @@ private function normalizePermissions(string $permissions): int return octdec(implode('', array_map($mapper, $parts))); } - /** - * @inheritdoc - * - * @param string $directory - */ private function listDirectoryContentsRecursive(string $directory): Generator { $location = $this->prefixer()->prefixPath($directory); @@ -583,9 +576,6 @@ private function ensureParentDirectoryExists(string $path, ?string $visibility): $this->ensureDirectoryExists($dirname, $visibility); } - /** - * @param string $dirname - */ private function ensureDirectoryExists(string $dirname, ?string $visibility): void { $connection = $this->connection();