Skip to content

Commit

Permalink
style: [FTP] update method usages to PHP 8.0
Browse files Browse the repository at this point in the history
  • Loading branch information
tinect committed Feb 3, 2024
1 parent 9cf97ff commit 67086c1
Showing 1 changed file with 4 additions and 14 deletions.
18 changes: 4 additions & 14 deletions src/Ftp/FtpAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'] ?? '');
}

Expand Down Expand Up @@ -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
Expand All @@ -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();
}
Expand All @@ -484,19 +482,14 @@ 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));
};

// converts to decimal number
return octdec(implode('', array_map($mapper, $parts)));
}

/**
* @inheritdoc
*
* @param string $directory
*/
private function listDirectoryContentsRecursive(string $directory): Generator
{
$location = $this->prefixer()->prefixPath($directory);
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 67086c1

Please sign in to comment.