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

ItemArrayCaster   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 11
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
eloc 6
c 1
b 0
f 0
dl 0
loc 11
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A cast() 0 9 2
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