| Total Complexity | 6 |
| Total Lines | 41 |
| Duplicated Lines | 0 % |
| Coverage | 100% |
| Changes | 2 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 13 | final class KeyValue implements Factory |
||
| 14 | { |
||
| 15 | /** |
||
| 16 | * @var ValueTransformer |
||
| 17 | */ |
||
| 18 | private $transformer; |
||
| 19 | |||
| 20 | 5 | public function __construct(ValueTransformer $transformer) |
|
| 23 | 5 | } |
|
| 24 | |||
| 25 | /** |
||
| 26 | * {@inheritdoc} |
||
| 27 | * |
||
| 28 | * @throw InvalidArgumentException if there is some problem with the config. |
||
| 29 | */ |
||
| 30 | 2 | public function create(string $name, array $config): Dictionary |
|
| 31 | { |
||
| 32 | 2 | if (!isset($config['content'])) { |
|
| 33 | 1 | throw new InvalidArgumentException(sprintf( |
|
| 34 | 1 | 'The key content for dictionary %s must be set.', |
|
| 35 | $name |
||
| 36 | )); |
||
| 37 | } |
||
| 38 | |||
| 39 | 1 | $content = $config['content']; |
|
| 40 | 1 | $values = []; |
|
| 41 | |||
| 42 | 1 | foreach ($content as $key => $value) { |
|
| 43 | 1 | $builtValue = $this->transformer->transform($value); |
|
| 44 | 1 | $key = $this->transformer->transform($key); |
|
| 45 | 1 | $values[$key] = $builtValue; |
|
| 46 | } |
||
| 47 | |||
| 48 | 1 | return new Simple($name, $values); |
|
| 49 | } |
||
| 50 | |||
| 51 | 1 | public function supports(array $config): bool |
|
| 54 | } |
||
| 55 | } |
||
| 56 |