Skip to content

Commit 25af541

Browse files
author
Alexander Lentner
committed
Add support for PHP 8.3 and 8.4
1 parent 20583a8 commit 25af541

11 files changed

+49
-39
lines changed

Diff for: .github/workflows/ci.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ jobs:
1212
strategy:
1313
fail-fast: true
1414
matrix:
15-
php: [ "8.0", "8.1", "8.2" ]
15+
php: [ "8.0", "8.1", "8.2", "8.3", "8.4" ]
1616

1717
runs-on: ubuntu-latest
1818
name: PHP@${{ matrix.php }}

Diff for: .gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -2,5 +2,6 @@ vendor/
22
coverage/
33
composer.lock
44
.phpunit.result.cache
5+
.phpunit.cache
56
coverage.xml
67
junit.xml

Diff for: CHANGELOG.md

+8
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,14 @@ All notable changes to this project will be documented in this file.
44
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
55
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
66

7+
## [5.0.1] - 2025-01-09
8+
### Added
9+
- Support for PHP 8.3. and PHP 8.4.
10+
11+
### Changed
12+
- Code improvements to avoid type errors on runtime
13+
- Implicitly nullable parameters to nullable (PHP 8.4 deprecation)
14+
715
## [5.0.0] - 2023-03-01
816
### Added
917
- Support for PHP 8.2.

Diff for: composer.json

+3-3
Original file line numberDiff line numberDiff line change
@@ -21,13 +21,13 @@
2121
}
2222
},
2323
"require": {
24-
"php": "8.0.* | 8.1.* | 8.2.*",
24+
"php": "8.0.* | 8.1.* | 8.2.* | 8.3.* | 8.4.*",
2525
"php-di/phpdoc-reader": "^2.1"
2626
},
2727
"require-dev": {
2828
"laravel/pint": "^1.5 | ^1.6",
29-
"pestphp/pest": "^1.22",
30-
"phpstan/phpstan": "^1.10"
29+
"pestphp/pest": "^1.22 | ^2.0 | ^3.0",
30+
"phpstan/phpstan": "^1.10 | ^2.0"
3131
},
3232
"scripts": {
3333
"analyse": "phpstan analyse --memory-limit 512M",

Diff for: phpstan.neon

+3-1
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,6 @@ parameters:
22
paths:
33
- src
44
level: max
5-
checkMissingIterableValueType: false
5+
checkExplicitMixed: false
6+
ignoreErrors:
7+
- identifier: missingType.iterableValue

Diff for: phpunit.xml

+11-15
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,13 @@
11
<?xml version="1.0" encoding="UTF-8"?>
2-
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3-
xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd"
4-
colors="true"
5-
verbose="true"
6-
>
7-
<testsuites>
8-
<testsuite name="Json Decoder Test Suite">
9-
<directory>./tests</directory>
10-
</testsuite>
11-
</testsuites>
12-
<coverage processUncoveredFiles="true">
13-
<include>
14-
<directory suffix=".php">./src</directory>
15-
</include>
16-
</coverage>
2+
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="./vendor/phpunit/phpunit/phpunit.xsd" colors="true" cacheDirectory=".phpunit.cache">
3+
<testsuites>
4+
<testsuite name="Json Decoder Test Suite">
5+
<directory>./tests</directory>
6+
</testsuite>
7+
</testsuites>
8+
<source>
9+
<include>
10+
<directory suffix=".php">./src</directory>
11+
</include>
12+
</source>
1713
</phpunit>

Diff for: src/Bindings/DateTimeBinding.php

+8-3
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@ public function __construct(
2222
public function validate(array $jsonData): bool
2323
{
2424
if ($this->jsonField && array_key_exists($this->jsonField, $jsonData) && ! empty($jsonData[$this->jsonField])) {
25+
if (! is_string($jsonData[$this->jsonField])) {
26+
return false;
27+
}
2528
return DateTime::createFromFormat($this->dateTimeFormat, $jsonData[$this->jsonField]) !== false;
2629
}
2730

@@ -31,10 +34,12 @@ public function validate(array $jsonData): bool
3134
public function bind(JsonDecoder $jsonDecoder, Property $property, array $jsonData = []): void
3235
{
3336
if ($this->jsonField && array_key_exists($this->jsonField, $jsonData)) {
34-
$dateTimeObject = DateTime::createFromFormat($this->dateTimeFormat, $jsonData[$this->jsonField]);
37+
if (is_string($jsonData[$this->jsonField])) {
38+
$dateTimeObject = DateTime::createFromFormat($this->dateTimeFormat, $jsonData[$this->jsonField]);
3539

36-
if ($dateTimeObject !== false) {
37-
$property->set($dateTimeObject);
40+
if ($dateTimeObject !== false) {
41+
$property->set($dateTimeObject);
42+
}
3843
}
3944
}
4045
}

Diff for: src/Bindings/FieldBinding.php

+3-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,9 @@ public function bind(JsonDecoder $jsonDecoder, Property $property, array $jsonDa
1212
{
1313
if ($this->jsonField && array_key_exists($this->jsonField, $jsonData) && $this->type) {
1414
$data = $jsonData[$this->jsonField];
15-
$property->set($jsonDecoder->decodeArray($data, $this->type));
15+
if (is_null($data) || is_array($data)) {
16+
$property->set($jsonDecoder->decodeArray($data, $this->type));
17+
}
1618
}
1719
}
1820
}

Diff for: src/JsonDecoder.php

+3-3
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@ public function scanAndRegister(string $class): void
6060
* @throws JsonValueException
6161
* @throws ReflectionException
6262
*/
63-
public function decode(string $json, string $classType, string $root = null): mixed
63+
public function decode(string $json, string $classType, ?string $root = null): mixed
6464
{
6565
return $this->decodeArray($this->parseJson($json, $root), $classType);
6666
}
@@ -73,13 +73,13 @@ public function decode(string $json, string $classType, string $root = null): mi
7373
* @throws JsonValueException
7474
* @throws ReflectionException
7575
*/
76-
public function decodeMultiple(string $json, string $classType, string $root = null): array
76+
public function decodeMultiple(string $json, string $classType, ?string $root = null): array
7777
{
7878
$data = $this->parseJson($json, $root);
7979

8080
return array_map(
8181
function ($element) use ($classType) {
82-
return $this->decodeArray($element, $classType);
82+
return is_array($element) ? $this->decodeArray($element, $classType) : $this->decodeArray(null, $classType);
8383
},
8484
$data
8585
);

Diff for: src/Property.php

+4-2
Original file line numberDiff line numberDiff line change
@@ -108,8 +108,10 @@ private function typesMatch(?ReflectionType $reflectionType, mixed $value): bool
108108

109109
if ($reflectionType instanceof ReflectionUnionType) {
110110
foreach ($reflectionType->getTypes() as $type) {
111-
if ($type->getName() === $valueType) {
112-
return true;
111+
if ($type instanceof ReflectionNamedType) {
112+
if ($type->getName() === $valueType) {
113+
return true;
114+
}
113115
}
114116
}
115117
}

Diff for: tests/PropertyTest.php

+4-10
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,11 @@
1414
expect($sample->{$propertyName})->toEqual('value');
1515
}
1616
})->with([
17-
'public' => [
18-
'name' => 'publicProperty',
19-
],
20-
'protected' => [
21-
'name' => 'protectedProperty',
22-
],
23-
'private' => [
24-
'name' => 'privateProperty',
25-
],
17+
'public' => ['publicProperty'],
18+
'protected' => ['protectedProperty'],
19+
'private' => ['privateProperty'],
2620
'new' => [
27-
'name' => 'newProperty',
21+
'newProperty',
2822
'methodAccess' => false,
2923
],
3024
]);

0 commit comments

Comments
 (0)