Completed
Push — master ( 0cffd3...28f6d0 )
by Andrii
02:21
created

AddTagLinks   A

Complexity

Total Complexity 9

Size/Duplication

Total Lines 43
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
c 0
b 0
f 0
lcom 0
cbo 2
dl 0
loc 43
ccs 21
cts 21
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
B run() 0 11 5
A generateTagHref() 0 18 4
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));
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?

If you access a property on an interface, you most likely code against a concrete implementation of the interface.

Available Fixes

  1. Adding an additional type check:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeInterface $object) {
        if ($object instanceof SomeClass) {
            $a = $object->a;
        }
    }
    
  2. Changing the type hint:

    interface SomeInterface { }
    class SomeClass implements SomeInterface {
        public $a;
    }
    
    function someFunction(SomeClass $object) {
        $a = $object->a;
    }
    
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