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

ConsoleConfig   A

Complexity

Total Complexity 22

Size/Duplication

Total Lines 79
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 22
dl 0
loc 79
c 0
b 0
f 0
rs 10

6 Methods

Rating   Name   Duplication   Size   Complexity  
A getDirectories() 0 3 1
A getExcludeRegex() 0 3 1
A getIncludeRegex() 0 3 1
D validate() 0 32 17
A hasIgnore() 0 3 1
A hasOverwrite() 0 3 1
1
<?php
2
3
namespace PhpUnitGen\Configuration;
4
5
use PhpUnitGen\Exception\InvalidConfigException;
6
7
/**
8
 * Class ConsoleConfig.
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 ConsoleConfig extends BaseConfig implements ConsoleConfigInterface
17
{
18
    /**
19
     * {@inheritdoc}
20
     */
21
    protected function validate($config): void
22
    {
23
        parent::validate($config);
24
25
        // Check boolean parameters
26
        if (! isset($config['overwrite']) || ! is_bool($config['overwrite'])) {
27
            throw new InvalidConfigException('"overwrite" parameter must be set as a boolean.');
28
        }
29
30
        if (! isset($config['auto']) || ! is_bool($config['auto'])) {
31
            throw new InvalidConfigException('"auto" parameter must be set as a boolean.');
32
        }
33
        if (! isset($config['ignore']) || ! is_bool($config['ignore'])) {
34
            throw new InvalidConfigException('"ignore" parameter must be set as a boolean.');
35
        }
36
37
        // Check string parameters
38
        if (! isset($config['include']) || ! is_string($config['include'])) {
39
            throw new InvalidConfigException('"include" parameter must be set as a string.');
40
        }
41
        if (! isset($config['exclude']) || ! is_string($config['exclude'])) {
42
            throw new InvalidConfigException('"exclude" parameter must be set as a string.');
43
        }
44
45
        // Check that dirs exists
46
        if (! isset($config['dirs']) || ! is_array($config['dirs']) || count($config['dirs']) < 1) {
47
            throw new InvalidConfigException('"dirs" parameter is not an array or does not contains elements.');
48
        }
49
        // Validate dirs
50
        foreach ($config['dirs'] as $srcDir => $testsDir) {
51
            if (! is_string($srcDir) || ! is_string($testsDir)) {
52
                throw new InvalidConfigException('Some directories in "dirs" parameter are not strings.');
53
            }
54
        }
55
    }
56
57
    /**
58
     * {@inheritdoc}
59
     */
60
    public function hasOverwrite(): bool
61
    {
62
        return $this->config['overwrite'];
63
    }
64
65
    /**
66
     * {@inheritdoc}
67
     */
68
    public function hasIgnore(): bool
69
    {
70
        return $this->config['ignore'];
71
    }
72
73
    /**
74
     * {@inheritdoc}
75
     */
76
    public function getIncludeRegex(): string
77
    {
78
        return $this->config['include'];
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84
    public function getExcludeRegex(): string
85
    {
86
        return $this->config['exclude'];
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92
    public function getDirectories(): array
93
    {
94
        return $this->config['dirs'];
95
    }
96
}
97