Completed
Push — master ( 11a376...8d38b3 )
by Andrii
03:54
created

AddInitTag::run()   B

Complexity

Conditions 8
Paths 11

Size

Total Lines 19
Code Lines 11

Duplication

Lines 6
Ratio 31.58 %

Code Coverage

Tests 18
CRAP Score 8

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 6
loc 19
ccs 18
cts 18
cp 1
rs 7.7777
cc 8
eloc 11
nc 11
nop 1
crap 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\modifiers;
12
13
use hiqdev\chkipper\history\History;
14
use hiqdev\chkipper\history\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 View Code Duplication
                    foreach ($note->getCommits() as $commit) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
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