RemoveCommitLinks::run()   A
last analyzed

Complexity

Conditions 5
Paths 4

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 5.2

Importance

Changes 0
Metric Value
cc 5
eloc 4
nc 4
nop 1
dl 0
loc 6
ccs 4
cts 5
cp 0.8
crap 5.2
rs 9.6111
c 0
b 0
f 0
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 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