Application   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 5

Test Coverage

Coverage 0%

Importance

Changes 0
Metric Value
wmc 7
lcom 0
cbo 5
dl 0
loc 47
ccs 0
cts 40
cp 0
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B run() 0 35 6
A options() 0 8 1
1
<?php
2
3
namespace IntegerNet\TodoReminder;
4
5
use Gitonomy\Git\Repository;
6
use PhpParser\ParserFactory;
7
8
class Application
9
{
10
    public function run(): int
11
    {
12
        $options = $this->options();
13
14
        $repository = new Repository($options['root'] . '');
15
        $head = $repository->getHead();
16
        if ($head === null) {
17
            echo "TodoReminder cannot determine HEAD of repository";
18
            return 1;
19
        }
20
        $files = $head->getCommit()->getDiff()->getFiles();
21
        if (empty($files)) {
22
            echo "TodoReminder found no files to check";
23
            return 0;
24
        }
25
        $fileInspector = new FileInspector(
26
            $repository,
27
            (new ParserFactory())->create(ParserFactory::ONLY_PHP7)
28
        );
29
        $comments = new TodoComments();
30
        foreach ($files as $file) {
31
            /** @var \Gitonomy\Git\Diff\File $file */
32
            $fullPath = $repository->getWorkingDir() . '/' . $file->getName();
33
            if (file_exists($fullPath)) {
34
                $comments->add($fileInspector->findTodoComments($file->getName()));
35
            }
36
        }
37
        if ($comments->notEmpty()) {
38
            echo $comments->formatText(), "\n";
39
            return 0;
40
        }
41
42
        echo "TodoReminder has nothing to say.\n";
43
        return 0;
44
    }
45
46
    private function options(): array
47
    {
48
        $cliArguments = getopt('', ['root']);
49
        $defaults = [
50
            'root' => getcwd()
51
        ];
52
        return $cliArguments + $defaults;
53
    }
54
}
55