| Total Complexity | 6 |
| Total Lines | 45 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 16 | class BaseConfig implements ConfigInterface |
||
| 17 | { |
||
| 18 | /** |
||
| 19 | * @var array $config The configuration as an array. |
||
| 20 | */ |
||
| 21 | protected $config = []; |
||
| 22 | |||
| 23 | /** |
||
| 24 | * ArrayConfig constructor. |
||
| 25 | * |
||
| 26 | * @param mixed $config The config array to use. |
||
| 27 | */ |
||
| 28 | public function __construct($config) |
||
| 29 | { |
||
| 30 | $this->validate($config); |
||
| 31 | |||
| 32 | $this->config = $config; |
||
| 33 | } |
||
| 34 | |||
| 35 | /** |
||
| 36 | * Validate a configuration to know if it can be used to construct an instance. |
||
| 37 | * |
||
| 38 | * @param mixed $config The configuration to validate. |
||
| 39 | * |
||
| 40 | * @throws InvalidConfigException If the $config is invalid. |
||
| 41 | */ |
||
| 42 | protected function validate($config): void |
||
| 43 | { |
||
| 44 | // Check that $config is an array |
||
| 45 | if (! is_array($config)) { |
||
| 46 | throw new InvalidConfigException('The config must be an array.'); |
||
| 47 | } |
||
| 48 | |||
| 49 | // Check boolean parameters |
||
| 50 | if (! isset($config['interface']) || ! is_bool($config['interface'])) { |
||
| 51 | throw new InvalidConfigException('"interface" parameter must be set as a boolean.'); |
||
| 52 | } |
||
| 53 | } |
||
| 54 | |||
| 55 | /** |
||
| 56 | * {@inheritdoc} |
||
| 57 | */ |
||
| 58 | public function hasInterfaceParsing(): bool |
||
| 61 | } |
||
| 62 | } |
||
| 63 |