Passed
Push — develop ( 45600c...ff69f6 )
by Paul
03:16
created

BaseConfig::validate()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 10
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 10
c 0
b 0
f 0
rs 9.2
cc 4
eloc 4
nc 3
nop 1
1
<?php
2
3
namespace PhpUnitGen\Configuration;
4
5
use PhpUnitGen\Exception\InvalidConfigException;
6
7
/**
8
 * Class BaseConfig.
9
 *
10
 * @author     Paul Thébaud <[email protected]>.
11
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
12
 * @license    https://opensource.org/licenses/MIT The MIT license.
13
 * @link       https://github.com/paul-thebaud/phpunit-generator
14
 * @since      Class available since Release 2.0.0.
15
 */
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
59
    {
60
        return $this->config['interface'];
61
    }
62
}
63