AddTagLinks::generateTagHref()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 4

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 4
eloc 9
nc 4
nop 3
dl 0
loc 17
ccs 11
cts 11
cp 1
crap 4
rs 9.9666
c 1
b 0
f 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\lib\modifiers;
12
13
use hiqdev\chkipper\lib\History;
14
15
/**
16
 * Modifier that adds links for tags.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class AddTagLinks extends AbstractModifier
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function run(History $history)
26
    {
27 2
        $prev = null;
28 2
        foreach ($history->getTags() as $tag) {
29 2
            $tag = $tag->getName();
30 2
            if ($prev && ($history->isLastTag($prev) || !$history->hasLink($prev))) {
31 2
                $history->addLink($prev, static::generateTagHref($history, $prev, $tag));
0 ignored issues
show
Bug introduced by
$prev of type void is incompatible with the type string expected by parameter $prev of hiqdev\chkipper\lib\modi...inks::generateTagHref(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

31
                $history->addLink($prev, static::generateTagHref($history, /** @scrutinizer ignore-type */ $prev, $tag));
Loading history...
Bug Best Practice introduced by
The method hiqdev\chkipper\lib\modi...inks::generateTagHref() is not static, but was called statically. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

31
                $history->addLink($prev, static::/** @scrutinizer ignore-call */ generateTagHref($history, $prev, $tag));
Loading history...
32 2
            }
33 2
            $prev = $tag;
34 2
        }
35 2
    }
36
37
    /**
38
     * Generate href to a version tag.
39
     * @param History $history history object
40
     * @param string $prev previous tag
41
     * @param string $curr current tag
42
     * @return string
43
     */
44 2
    public function generateTagHref(History $history, $prev, $curr)
45
    {
46 2
        $project = $history->getProject();
47 2
        $rmsSite = $history->getConfig()->rmsSite;
0 ignored issues
show
Bug introduced by
Accessing rmsSite on the interface hiqdev\chkipper\lib\ConfigInterface suggest that you code against a concrete implementation. How about adding an instanceof check?
Loading history...
48
49 2
        if ($history->isInitTag($curr)) {
50 2
            if ($history->isLastTag($prev)) {
51 1
                return "https://$rmsSite/$project/releases";
52
            }
53
54 1
            return "https://$rmsSite/$project/releases/tag/$prev";
55
        }
56 1
        if ($history->isLastTag($prev)) {
57 1
            $prev = 'HEAD';
58 1
        }
59
60 1
        return "https://$rmsSite/$project/compare/$curr...$prev";
61
    }
62
}
63