Passed
Push — master ( 073e4f...921929 )
by Brian
09:51
created

ItemArrayCaster::cast()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 5
c 1
b 0
f 0
dl 0
loc 9
rs 10
cc 2
nc 2
nop 1
1
<?php
2
3
namespace Bmatovu\Ussd\Dto;
4
5
use Spatie\DataTransferObject\Caster;
6
7
class ItemArrayCaster implements Caster
8
{
9
    public function cast(mixed $values): array
10
    {
11
        if (! \is_array($values)) {
12
            throw new \Exception('Can only cast arrays to Item');
13
        }
14
15
        return array_map(function ($value) {
16
            return new Item($value);
17
        }, $values);
18
    }
19
}
20