Skip to content

Commit

Permalink
refactor: extract getDateTimeFormat() method
Browse files Browse the repository at this point in the history
  • Loading branch information
kenjis committed Jul 29, 2024
1 parent c24497d commit c68a3fb
Showing 1 changed file with 9 additions and 9 deletions.
18 changes: 9 additions & 9 deletions system/DataCaster/Cast/DatetimeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,7 @@ public static function get(
/**
* @see https://www.php.net/manual/en/datetimeimmutable.createfromformat.php#datetimeimmutable.createfromformat.parameters
*/
$format = match ($params[0] ?? '') {
'' => $helper->dateFormat['datetime'],
'ms' => $helper->dateFormat['datetime-ms'],
'us' => $helper->dateFormat['datetime-us'],
default => throw new InvalidArgumentException('Invalid parameter: ' . $params[0]),
};
$format = self::getDateTimeFormat($params, $helper);

return Time::createFromFormat($format, $value);
}
Expand All @@ -68,13 +63,18 @@ public static function set(
throw new InvalidArgumentException($message);
}

$format = match ($params[0] ?? '') {
$format = self::getDateTimeFormat($params, $helper);

return $value->format($format);
}

protected static function getDateTimeFormat(array $params, BaseConnection $helper): string

Check failure on line 71 in system/DataCaster/Cast/DatetimeCast.php

View workflow job for this annotation

GitHub Actions / PHP Static Analysis

Method CodeIgniter\DataCaster\Cast\DatetimeCast::getDateTimeFormat() has parameter $params with no value type specified in iterable type array.
{
return match ($params[0] ?? '') {
'' => $helper->dateFormat['datetime'],
'ms' => $helper->dateFormat['datetime-ms'],
'us' => $helper->dateFormat['datetime-us'],
default => throw new InvalidArgumentException('Invalid parameter: ' . $params[0]),
};

return $value->format($format);
}
}

0 comments on commit c68a3fb

Please sign in to comment.