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

Todolo::getStandardConfig()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 5
ccs 0
cts 5
cp 0
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Todolo\Command;
6
7
use Symfony\Component\Console\Command\Command;
8
use Symfony\Component\Console\Input\InputInterface;
9
use Symfony\Component\Console\Output\OutputInterface;
10
use Todolo\Helper\ConfigHelper;
11
use Todolo\Helper\OutputHelper;
12
use Todolo\TodoFinder;
13
14
class Todolo extends Command
15
{
16
    protected static $defaultName = 'todolo';
17
18
    /**
19
     * @var string
20
     */
21
    protected $configFilename = '.todolo.php';
22
23
    /**
24
     * @var ConfigHelper
25
     */
26
    protected $configHelper;
27
28
    /**
29
     * @var OutputHelper
30
     */
31
    protected $outputHelper;
32
33
    /**
34
     * @var TodoFinder
35
     */
36
    protected $todoFinder;
37
38
    public function __construct(
39
        ConfigHelper $configHelper,
40
        OutputHelper $outputHelper,
41
        TodoFinder $todoFinder,
42
        string $name = null
43
    ) {
44
        parent::__construct($name);
45
46
        $this->configHelper = $configHelper;
47
        $this->outputHelper = $outputHelper;
48
        $this->todoFinder = $todoFinder;
49
    }
50
51
    protected function execute(InputInterface $input, OutputInterface $output): int
52
    {
53
        $currentDir = getcwd();
54
        $config = $this->configHelper->getStandardConfig();
55
56
        if (file_exists($currentDir.'/'.$this->configFilename)) {
57
            $userConfig = (array) require $currentDir.'/'.$this->configFilename;
58
59
            // user config overrides standard config
60
            $config = array_merge($config, $userConfig);
61
        }
62
63
        $this->configHelper->validateConfig($config);
64
65
        $todos = [];
66
67
        // per dir ...
68
        foreach ($config['dirs_to_check'] as $dir) {
69
            $dirPath = $currentDir.'/'.$dir;
70
71
            $todos[$dir] = $this->todoFinder->getAllTodosForPHPFilesIn($dirPath);
72
        }
73
74
        $this->outputHelper->printTodos($output, $todos, $config);
75
76
        return 0;
77
    }
78
}
79