AddInitTag::run()   B
last analyzed

Complexity

Conditions 8
Paths 11

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 8

Importance

Changes 0
Metric Value
cc 8
eloc 10
nc 11
nop 1
dl 0
loc 16
ccs 15
cts 15
cp 1
crap 8
rs 8.4444
c 0
b 0
f 0
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