AddInitTag   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 11
dl 0
loc 18
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0
wmc 8

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 16 8
1
<?php
2
/**
3
 * Changelog keeper
4
 *
5
 * @link      https://github.com/hiqdev/chkipper
6
 * @package   chkipper
7
 * @license   BSD-3-Clause
8
 * @copyright Copyright (c) 2016-2017, HiQDev (http://hiqdev.com/)
9
 */
10
11
namespace hiqdev\chkipper\lib\modifiers;
12
13
use hiqdev\chkipper\lib\History;
14
use hiqdev\chkipper\lib\Tag;
15
16
/**
17
 * Modifier that adds init tag with oldest commit date.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class AddInitTag extends AbstractModifier
22
{
23 2
    public function run(History $history)
24
    {
25 2
        if (!$history->hasTag($history->initTag)) {
26 1
            $min = '';
27 1
            foreach ($history->getTags() as $tag) {
28 1
                foreach ($tag->getNotes() as $note) {
29 1
                    foreach ($note->getCommits() as $commit) {
30 1
                        $date = $commit->getDate();
31 1
                        if (!$min || strcmp($date, $min) < 0) {
32 1
                            $min = $date;
33 1
                        }
34 1
                    }
35 1
                }
36 1
            }
37 1
            if ($min) {
38 1
                $history->addTag(new Tag($history->initTag, $min));
39 1
            }
40 1
        }
41 2
    }
42
}
43