Skip to content

Commit 4d3b8a6

Browse files
authored
fix: Php 8.1 support (#53)
* Updated league/fractal to 0.20.0. Updated Fractal::jsonSerialize return type to match the JsonSerializable interface. Updated TraversableClass::getIterator() to match the IteratorAggregate interface. * Updated php minimum supported version from 7.3 to 7.4 * Updated `ArraySerializer::collection` type hints * Resolved issues with broken tests.
1 parent 13e9239 commit 4d3b8a6

File tree

6 files changed

+8
-7
lines changed

6 files changed

+8
-7
lines changed

composer.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@
1919
}
2020
],
2121
"require": {
22-
"php": "^7.3|^8.0",
23-
"league/fractal": "^0.19.0"
22+
"php": "^7.4|^8.0",
23+
"league/fractal": "^0.20.0"
2424
},
2525
"require-dev": {
2626
"illuminate/pagination": "~5.3.0|~5.4.0",

src/ArraySerializer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class ArraySerializer extends BaseArraySerializer
1414
*
1515
* @return array
1616
*/
17-
public function collection($resourceKey, array $data)
17+
public function collection(string $resourceKey, array $data): array
1818
{
1919
return $data;
2020
}

src/Fractal.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ public function getResourceName()
455455
/**
456456
* Convert the object into something JSON serializable.
457457
*/
458-
public function jsonSerialize()
458+
public function jsonSerialize(): mixed
459459
{
460460
return $this->toArray();
461461
}

tests/TestTransformer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestTransformer extends TransformerAbstract
1111
*
1212
* @var array
1313
*/
14-
protected $availableIncludes = [
14+
protected array $availableIncludes = [
1515
'characters',
1616
'publisher',
1717
];

tests/TestTransformerWithIncludes.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ class TestTransformerWithIncludes extends TransformerAbstract
1111
*
1212
* @var array
1313
*/
14-
protected $defaultIncludes = [
14+
protected array $defaultIncludes = [
1515
'characters',
1616
'publisher',
1717
'title',

tests/TraversableClass.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44

55
use ArrayIterator;
66
use IteratorAggregate;
7+
use Traversable;
78

89
class TraversableClass implements IteratorAggregate
910
{
@@ -18,7 +19,7 @@ public function __construct(array $items)
1819
/**
1920
* @return array
2021
*/
21-
public function getIterator()
22+
public function getIterator(): Traversable
2223
{
2324
return new ArrayIterator($this->items);
2425
}

0 commit comments

Comments
 (0)