diff --git a/src/Ftp/FtpAdapter.php b/src/Ftp/FtpAdapter.php index 079dd010a..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(); @@ -634,9 +624,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; } /**