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