Skip to content

Commit

Permalink
Merge pull request #9105 from kenjis/fix-Time-createFromTimestamp
Browse files Browse the repository at this point in the history
fix: Time::createFromTimestamp() change for PHP 8.4
  • Loading branch information
kenjis authored Aug 20, 2024
2 parents a13c588 + 06b02bb commit 0a15e7b
Show file tree
Hide file tree
Showing 13 changed files with 148 additions and 76 deletions.
24 changes: 0 additions & 24 deletions phpstan-baseline.php
Original file line number Diff line number Diff line change
Expand Up @@ -7483,18 +7483,6 @@
'count' => 1,
'path' => __DIR__ . '/system/I18n/Time.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimestamp\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/system/I18n/Time.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimezone\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/system/I18n/Time.php',
];
$ignoreErrors[] = [
// identifier: ternary.shortNotAllowed
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
Expand All @@ -7507,18 +7495,6 @@
'count' => 1,
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimestamp\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
];
$ignoreErrors[] = [
// identifier: method.childReturnType
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimezone\\(\\)$#',
'count' => 1,
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
];
$ignoreErrors[] = [
// identifier: ternary.shortNotAllowed
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
Expand Down
2 changes: 1 addition & 1 deletion system/DataCaster/Cast/TimestampCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public static function get(
self::invalidTypeValueError($value);
}

return Time::createFromTimestamp((int) $value);
return Time::createFromTimestamp((int) $value, date_default_timezone_get());
}

public static function set(
Expand Down
2 changes: 1 addition & 1 deletion system/Entity/Cast/DatetimeCast.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static function get($value, array $params = [])
}

if (is_numeric($value)) {
return Time::createFromTimestamp((int) $value);
return Time::createFromTimestamp((int) $value, date_default_timezone_get());
}

if (is_string($value)) {
Expand Down
2 changes: 2 additions & 0 deletions system/I18n/Time.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* @property-read string $weekOfYear
* @property-read string $year
*
* @phpstan-consistent-constructor
*
* @see \CodeIgniter\I18n\TimeTest
*/
class Time extends DateTimeImmutable implements Stringable
Expand Down
2 changes: 2 additions & 0 deletions system/I18n/TimeLegacy.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,8 @@
* @property string $weekOfYear read-only
* @property string $year read-only
*
* @phpstan-consistent-constructor
*
* @deprecated Use Time instead.
* @see \CodeIgniter\I18n\TimeLegacyTest
*/
Expand Down
Loading

0 comments on commit 0a15e7b

Please sign in to comment.