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

ConfigHelper::validateConfig()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 4.5923

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 10
c 1
b 0
f 1
dl 0
loc 21
ccs 4
cts 6
cp 0.6667
rs 9.9332
cc 4
nc 5
nop 1
crap 4.5923
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