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

AddCommitLinks::generateCommitHref()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 6
ccs 3
cts 3
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
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
15
/**
16
 * Modifier that adds links for commits without link.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class AddCommitLinks extends AbstractModifier
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function run(History $history)
26
    {
27 2
        foreach ($history->getHashes() as $hash) {
28 2
            if (!$history->hasLink($hash)) {
29 1
                $history->addLink($hash, static::generateCommitHref($history, $hash));
30 1
            }
31 2
        }
32 2
    }
33
34
    /**
35
     * Generates href to a commit.
36
     * @param History $history history object
37
     * @param string $hash commit hash
38
     * @return string
39
     */
40 1
    public static function generateCommitHref(History $history, $hash)
41
    {
42 1
        $project = $history->getProject();
43
44 1
        return "https://github.com/$project/commit/$hash";
45
    }
46
}
47