Completed
Push — develop ( ff69f6...31e284 )
by Paul
02:14
created

ConsoleConfig::hasOverwrite()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
eloc 1
nc 1
nop 0
1
<?php
2
3
namespace PhpUnitGen\Configuration;
4
5
use PhpUnitGen\Exception\InvalidConfigException;
6
use Respect\Validation\Validator;
7
8
/**
9
 * Class ConsoleConfig.
10
 *
11
 * @author     Paul Thébaud <[email protected]>.
12
 * @copyright  2017-2018 Paul Thébaud <[email protected]>.
13
 * @license    https://opensource.org/licenses/MIT The MIT license.
14
 * @link       https://github.com/paul-thebaud/phpunit-generator
15
 * @since      Class available since Release 2.0.0.
16
 */
17
class ConsoleConfig extends BaseConfig implements ConsoleConfigInterface
18
{
19
    /**
20
     * {@inheritdoc}
21
     */
22
    protected function validate($config): void
23
    {
24
        parent::validate($config);
25
26
        // Check boolean parameters
27
        if (! Validator::key('overwrite', Validator::boolType())->validate($config)) {
28
            throw new InvalidConfigException('"overwrite" parameter must be set as a boolean.');
29
        }
30
31
        if (! Validator::key('auto', Validator::boolType())->validate($config)) {
32
            throw new InvalidConfigException('"auto" parameter must be set as a boolean.');
33
        }
34
        if (! Validator::key('ignore', Validator::boolType())->validate($config)) {
35
            throw new InvalidConfigException('"ignore" parameter must be set as a boolean.');
36
        }
37
38
        // Check string parameters
39
        if (! Validator::key('include', Validator::stringType())->validate($config)) {
40
            throw new InvalidConfigException('"include" parameter must be set as a string.');
41
        }
42
        if (! Validator::key('exclude', Validator::stringType())->validate($config)) {
43
            throw new InvalidConfigException('"exclude" parameter must be set as a string.');
44
        }
45
46
        // Check that dirs exists
47
        if (! Validator::key('dirs', Validator::arrayType()->length(1, null))->validate($config)) {
48
            throw new InvalidConfigException('"dirs" parameter is not an array or does not contains elements.');
49
        }
50
        // Validate each dirs
51
        if (! Validator::arrayVal()
52
            ->each(Validator::stringType(), Validator::stringType())->validate($config['dirs'])
53
        ) {
54
            throw new InvalidConfigException('Some directories in "dirs" parameter are not strings.');
55
        }
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function hasOverwrite(): bool
62
    {
63
        return $this->config['overwrite'];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69
    public function hasIgnore(): bool
70
    {
71
        return $this->config['ignore'];
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77
    public function getIncludeRegex(): string
78
    {
79
        return $this->config['include'];
80
    }
81
82
    /**
83
     * {@inheritdoc}
84
     */
85
    public function getExcludeRegex(): string
86
    {
87
        return $this->config['exclude'];
88
    }
89
90
    /**
91
     * {@inheritdoc}
92
     */
93
    public function getDirectories(): array
94
    {
95
        return $this->config['dirs'];
96
    }
97
}
98