| Total Complexity | 7 |
| Total Lines | 40 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 0 | ||
| 1 | <?php |
||
| 8 | class ScalarTransformerWalker implements ResultWalker |
||
| 9 | { |
||
| 10 | /** @var array */ |
||
| 11 | private $typeMapping; |
||
| 12 | |||
| 13 | /** |
||
| 14 | * @param array $typeMapping e.g: ['id' => 'int', 'active' => 'bool'] |
||
| 15 | */ |
||
| 16 | 5 | public function __construct(array $typeMapping) |
|
| 19 | 5 | } |
|
| 20 | |||
| 21 | public function walk(array $result): array |
||
| 22 | { |
||
| 23 | 3 | array_walk($result, function (&$value, $key) { |
|
| 24 | 3 | if ($value === null || !isset($this->typeMapping[$key])) { |
|
| 25 | 1 | return; |
|
| 26 | } |
||
| 27 | |||
| 28 | 2 | $value = $this->transform($value, $this->typeMapping[$key]); |
|
| 29 | 3 | }); |
|
| 30 | |||
| 31 | 2 | return $result; |
|
| 32 | } |
||
| 33 | |||
| 34 | 2 | private function transform($value, $type) |
|
| 48 | )); |
||
| 49 | } |
||
| 51 |