We could not synchronize checks via GitHub's checks API since Scrutinizer's GitHub App is not installed for this repository.
| Total Complexity | 7 |
| Total Lines | 35 |
| Duplicated Lines | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
| 1 | <?php |
||
| 12 | abstract class AbstractConfig |
||
| 13 | { |
||
| 14 | protected const NORMALIZERS = []; |
||
| 15 | |||
| 16 | public function __construct(array $config) |
||
| 17 | { |
||
| 18 | $this->populate($config); |
||
| 19 | } |
||
| 20 | |||
| 21 | protected function populate(array $config): void |
||
| 22 | { |
||
| 23 | foreach ($config as $key => $value) { |
||
| 24 | $property = lcfirst(str_replace('_', '', ucwords($key, '_'))); |
||
| 25 | $normalizer = static::NORMALIZERS[$property] ?? 'normalize'.ucfirst($property); |
||
| 26 | if (method_exists($this, $normalizer)) { |
||
| 27 | $this->$property = $this->$normalizer($value); |
||
| 28 | } elseif (property_exists($this, $property)) { |
||
| 29 | $this->$property = $value; |
||
| 30 | } else { |
||
| 31 | throw new InvalidArgumentException(sprintf('Unknown config "%s".', $property)); |
||
| 32 | } |
||
| 33 | } |
||
| 34 | } |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @param array|mixed $value |
||
| 38 | */ |
||
| 39 | protected function normalizeCallback($value): Callback |
||
| 40 | { |
||
| 41 | return new Callback($value); |
||
| 42 | } |
||
| 43 | |||
| 44 | protected function normalizeValidation(array $config): Validation |
||
| 47 | } |
||
| 48 | } |
||
| 49 |