Passed
Push — master ( 1ae59d...620d3f )
by Konrad
04:55
created

ConfigHelper::getStandardConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 6
c 0
b 0
f 0
dl 0
loc 10
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Todolo\Helper;
6
7
use Exception;
8
9
class ConfigHelper
10
{
11
    /**
12
     * @return array<string, array<int, string>|bool>
13
     */
14 2
    public function getStandardConfig(): array
15
    {
16
        return [
17
            'dirs_to_check' => [
18 2
                'src',
19
            ],
20
            // show
21
            'show_empty_dir' => false,
22
            'show_files_with_no_todos' => false,
23
            'show_no_files_info' => true,
24
        ];
25
    }
26
27
    /**
28
     * @param array<int|string, mixed> $config
29
     *
30
     * @throws Exception if a required field is not set
31
     */
32 4
    public function validateConfig(array $config): void
33
    {
34
        /*
35
         * check required config
36
         */
37
        foreach ([
38 4
            'dirs_to_check',
39
            'show_empty_dir',
40
            'show_files_with_no_todos',
41
            'show_no_files_info',
42
        ] as $key) {
43 4
            if (!isset($config[$key])) {
44 4
                throw new Exception('Field "'.$key.'" not set in config.');
45
            }
46
        }
47
48
        /*
49
         * setting: dirs_to_check
50
         */
51
        if (!\is_array($config['dirs_to_check'])) {
52
            throw new Exception('Field "dirs_to_check" is not of type array.');
53
        }
54
    }
55
}
56