Skip to content

Commit

Permalink
Support spatie/data-transfer-object ^3.5 (#10)
Browse files Browse the repository at this point in the history
  • Loading branch information
jessarcher committed Aug 19, 2021
1 parent 7bb33ba commit c93dbc9
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "big-picture-medical/openehr-data-structures",
"require": {
"spatie/data-transfer-object": "^3.3",
"spatie/data-transfer-object": "^3.5",
"symfony/finder": "^5.2",
"illuminate/support": "^8.21"
},
Expand Down
6 changes: 3 additions & 3 deletions src/TypeableArrayCaster.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,18 +9,18 @@
class TypeableArrayCaster implements Caster
{
public function __construct(
private $type,
private array $types,
private string $itemType,
) {
}

public function cast(mixed $value): mixed
{
if ($this->type !== 'array') {
if (count($this->types) !== 1 || $this->types[0] !== 'array') {
throw new RuntimeException('Can only cast arrays');
}

$caster = new TypeableDataTransferObjectCaster($this->itemType);
$caster = new TypeableDataTransferObjectCaster([$this->itemType]);

return array_map(fn ($item) => $this->validate($caster->cast($item)), $value);
}
Expand Down

0 comments on commit c93dbc9

Please sign in to comment.