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

RemoveCommitLinks   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 77.78%

Importance

Changes 0
Metric Value
wmc 5
c 0
b 0
f 0
lcom 1
cbo 2
dl 0
loc 18
ccs 7
cts 9
cp 0.7778
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 10 5
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 removes commit links that are not present in the history.
17
 * Has option to remove all the commit links.
18
 *
19
 * @author Andrii Vasyliev <[email protected]>
20
 */
21
class RemoveCommitLinks extends AbstractModifier
22
{
23
    public $all = false;
24
25
    /**
26
     * {@inheritdoc}
27
     */
28 2
    public function run(History $history)
29
    {
30 2
        foreach ($history->getLinks() as $link => $href) {
31 2
            if (preg_match('/^[0-9a-f]{7}$/', $link)) {
32 2
                if ($this->all || !$history->hasHash($link)) {
33
                    $history->removeLink($link);
34
                }
35 2
            }
36 2
        }
37 2
    }
38
}
39