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

ConfigHelper   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 5
eloc 17
c 1
b 0
f 1
dl 0
loc 44
ccs 6
cts 8
cp 0.75
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getStandardConfig() 0 10 1
A validateConfig() 0 21 4
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