Conditions | 6 |
Paths | 5 |
Total Lines | 25 |
Lines | 0 |
Ratio | 0 % |
Changes | 0 |
1 | <?php |
||
35 | public function format($value) |
||
36 | { |
||
37 | if (empty($value)) { |
||
38 | return $value; |
||
39 | } |
||
40 | |||
41 | if (!is_iterable($value)) { |
||
42 | throw new \InvalidArgumentException(sprintf( |
||
43 | 'Collection formatter requires value to be iterable, %s given', |
||
44 | is_object($value) ? get_class($value) : gettype($value) |
||
45 | )); |
||
46 | } |
||
47 | |||
48 | $formatted = []; |
||
49 | foreach ($value as $key => $val) { |
||
50 | $formattedValue = $val; |
||
51 | foreach ($this->formatters as $formatter) { |
||
52 | $formattedValue = $formatter->format($formattedValue); |
||
53 | } |
||
54 | |||
55 | $formatted[$key] = $formattedValue; |
||
56 | } |
||
57 | |||
58 | return $formatted; |
||
59 | } |
||
60 | } |
||
61 |