Skip to content

Commit 0a15e7b

Browse files
authored
Merge pull request #9105 from kenjis/fix-Time-createFromTimestamp
fix: Time::createFromTimestamp() change for PHP 8.4
2 parents a13c588 + 06b02bb commit 0a15e7b

File tree

13 files changed

+148
-76
lines changed

13 files changed

+148
-76
lines changed

phpstan-baseline.php

Lines changed: 0 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -7483,18 +7483,6 @@
74837483
'count' => 1,
74847484
'path' => __DIR__ . '/system/I18n/Time.php',
74857485
];
7486-
$ignoreErrors[] = [
7487-
// identifier: method.childReturnType
7488-
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimestamp\\(\\)$#',
7489-
'count' => 1,
7490-
'path' => __DIR__ . '/system/I18n/Time.php',
7491-
];
7492-
$ignoreErrors[] = [
7493-
// identifier: method.childReturnType
7494-
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\Time\\) of method CodeIgniter\\\\I18n\\\\Time\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTimeImmutable\\)\\) of method DateTimeImmutable\\:\\:setTimezone\\(\\)$#',
7495-
'count' => 1,
7496-
'path' => __DIR__ . '/system/I18n/Time.php',
7497-
];
74987486
$ignoreErrors[] = [
74997487
// identifier: ternary.shortNotAllowed
75007488
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',
@@ -7507,18 +7495,6 @@
75077495
'count' => 1,
75087496
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
75097497
];
7510-
$ignoreErrors[] = [
7511-
// identifier: method.childReturnType
7512-
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimestamp\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimestamp\\(\\)$#',
7513-
'count' => 1,
7514-
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
7515-
];
7516-
$ignoreErrors[] = [
7517-
// identifier: method.childReturnType
7518-
'message' => '#^Return type \\(CodeIgniter\\\\I18n\\\\TimeLegacy\\) of method CodeIgniter\\\\I18n\\\\TimeLegacy\\:\\:setTimezone\\(\\) should be covariant with return type \\(static\\(DateTime\\)\\) of method DateTime\\:\\:setTimezone\\(\\)$#',
7519-
'count' => 1,
7520-
'path' => __DIR__ . '/system/I18n/TimeLegacy.php',
7521-
];
75227498
$ignoreErrors[] = [
75237499
// identifier: ternary.shortNotAllowed
75247500
'message' => '#^Short ternary operator is not allowed\\. Use null coalesce operator if applicable or consider using long ternary\\.$#',

system/DataCaster/Cast/TimestampCast.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public static function get(
3232
self::invalidTypeValueError($value);
3333
}
3434

35-
return Time::createFromTimestamp((int) $value);
35+
return Time::createFromTimestamp((int) $value, date_default_timezone_get());
3636
}
3737

3838
public static function set(

system/Entity/Cast/DatetimeCast.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static function get($value, array $params = [])
4040
}
4141

4242
if (is_numeric($value)) {
43-
return Time::createFromTimestamp((int) $value);
43+
return Time::createFromTimestamp((int) $value, date_default_timezone_get());
4444
}
4545

4646
if (is_string($value)) {

system/I18n/Time.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* @property-read string $weekOfYear
4040
* @property-read string $year
4141
*
42+
* @phpstan-consistent-constructor
43+
*
4244
* @see \CodeIgniter\I18n\TimeTest
4345
*/
4446
class Time extends DateTimeImmutable implements Stringable

system/I18n/TimeLegacy.php

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@
3939
* @property string $weekOfYear read-only
4040
* @property string $year read-only
4141
*
42+
* @phpstan-consistent-constructor
43+
*
4244
* @deprecated Use Time instead.
4345
* @see \CodeIgniter\I18n\TimeLegacyTest
4446
*/

0 commit comments

Comments
 (0)