Skip to content

Commit a9e622b

Browse files
Fixed issue with DatePeriod failing against changes in PHP Release 8.2 (#171)
* #170 / PHP 8.1 to 8.2 update causes error with DateTimeRange Quick patch to fix the issue related to a ticket Release-ready patch for version 1.1.6
1 parent ef25097 commit a9e622b

File tree

4 files changed

+51
-14
lines changed

4 files changed

+51
-14
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,9 @@ SOFTWARE.
7272
```
7373
That will use native PHP mechanics for serialization, which should work properly
7474
starting from this release (1.1.3)
75-
2. Starting from the release 1.1.6 fixed the bug with timezones indirect params (this
76-
partially changes the logic, but initial logic before that release was broken).
75+
76+
[//]: # (2. Starting from the release 1.2.0 fixed the bug with timezones indirect params (this)
77+
[//]: # ( partially changes the logic, but initial logic before that release was broken).)
7778

7879
----
7980

@@ -97,7 +98,7 @@ so documentation will come after that in the very nearest time. My apologies.
9798

9899
Minimal PHP version: **8.0**
99100

100-
Current framework version: **1.1.5**
101+
Current framework version: **1.1.6**
101102

102103
```shell
103104
composer require spaf/simputils "^1"

src/PHP.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public static function frameworkDir() {
121121
*/
122122
public static function simpUtilsVersion(): Version|string {
123123
$class = static::redef(Version::class);
124-
return new $class('1.1.5', 'SimpUtils');
124+
return new $class('1.1.6', 'SimpUtils');
125125
}
126126

127127
/**

src/traits/MetaMagic.php

Lines changed: 22 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
namespace spaf\simputils\traits;
44

55
use JsonException;
6+
use ReflectionException;
67
use spaf\simputils\exceptions\InfiniteLoopPreventionExceptions;
78
use spaf\simputils\exceptions\MetaMagicStrictInheritanceProblem;
9+
use spaf\simputils\exceptions\PropertyDoesNotExist;
810
use spaf\simputils\FS;
911
use spaf\simputils\generic\BasicPrism;
1012
use spaf\simputils\generic\SimpleObject;
@@ -181,7 +183,7 @@ protected function _jsonFlags(bool $pretty = null) {
181183
* @param string $json Json string
182184
*
183185
* @return static
184-
* @throws \ReflectionException Reflection issues
186+
* @throws ReflectionException Reflection issues
185187
*/
186188
public static function fromJson(string $json): static {
187189
$data = json_decode($json, true);
@@ -404,8 +406,8 @@ private function _iterateConvertObjectsAndArrays(
404406
* By default is true
405407
*
406408
* @return object Always returns a new object of type provided as a first argument
407-
* @throws \ReflectionException Reflection issue
408-
* @throws \spaf\simputils\exceptions\MetaMagicStrictInheritanceProblem Strict Inheritance
409+
* @throws ReflectionException Reflection issue
410+
* @throws MetaMagicStrictInheritanceProblem Strict Inheritance
409411
* Problem
410412
*/
411413
public static function expandFrom(
@@ -433,7 +435,7 @@ public static function expandFrom(
433435
* @param array $data Array data for the class
434436
*
435437
* @return static
436-
* @throws \ReflectionException Reflection issues
438+
* @throws ReflectionException Reflection issues
437439
*/
438440
public static function fromArray(array $data): static {
439441
$class = static::class;
@@ -451,7 +453,7 @@ public static function fromArray(array $data): static {
451453
*
452454
* @return static
453455
*
454-
* @throws \ReflectionException Reflection Exception
456+
* @throws ReflectionException Reflection Exception
455457
*/
456458
public static function createDummy(): static {
457459
/** @noinspection PhpIncompatibleReturnTypeInspection */
@@ -478,15 +480,25 @@ protected static function ___l10n(array $data) {
478480
* @param array|Box $data Setup data
479481
*
480482
* @return $this
483+
* @throws ReflectionException
481484
*/
482485
protected function ___setup(array|Box $data): static {
483486
foreach ($data as $key => $val) {
484-
if (is_array($val) && !empty($val[PHP::$serialized_class_key_name])) {
485-
$obj = PHP::createDummy($val[PHP::$serialized_class_key_name]);
486-
unset($val[PHP::$serialized_class_key_name]);
487-
$val = PHP::metaMagicSpell($obj, 'setup', $val);
487+
// MARK Temporary hack to resolve unknown "properties" during setup,
488+
// https://github.com/PandaHugMonster/php-simputils/issues/170
489+
490+
// MARK This hack must be revised and the issue considered during redesign
491+
// of the engine
492+
try {
493+
if (is_array($val) && !empty($val[PHP::$serialized_class_key_name])) {
494+
$obj = PHP::createDummy($val[PHP::$serialized_class_key_name]);
495+
unset($val[PHP::$serialized_class_key_name]);
496+
$val = PHP::metaMagicSpell($obj, 'setup', $val);
497+
}
498+
$this->$key = $val;
499+
} catch (PropertyDoesNotExist) {
500+
// MARK Skipping setting up an unknown "property"
488501
}
489-
$this->$key = $val;
490502
}
491503
return $this;
492504
}

tests/general/bugs/BugTicket170.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
<?php
2+
3+
namespace general\bugs;
4+
5+
use PHPUnit\Framework\TestCase;
6+
use function spaf\simputils\basic\ts;
7+
8+
/**
9+
* @covers DatePeriod
10+
*/
11+
class BugTicket170 extends TestCase {
12+
13+
function testMain() {
14+
$point = "2023-11-17 17:00:00";
15+
$ts = ts($point);
16+
$period = $ts->period("-24 hours");
17+
18+
$this->assertEquals("2023-11-16 17:00:00", $period->start);
19+
$this->assertEquals($point, $period->end);
20+
21+
$this->assertEquals("2023-11-16 17:00:00 - {$ts}", "{$period}");
22+
}
23+
24+
}

0 commit comments

Comments
 (0)