AddAuthorLinks::run()   B
last analyzed

Complexity

Conditions 8
Paths 25

Size

Total Lines 16
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 46.7792

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 8
eloc 10
nc 25
nop 1
dl 0
loc 16
ccs 2
cts 13
cp 0.1538
crap 46.7792
rs 8.4444
c 1
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 adds links for authors given in config.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class AddAuthorLinks extends AbstractModifier
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25 2
    public function run(History $history)
26
    {
27 2
        foreach (array_reverse($history->getConfig()->getAuthors()) as $nick => $data) {
28
            if (strncmp($nick, '@', 1)) {
29
                $nick = '@' . $nick;
30
            }
31
            $href = !empty($data['github']) ? $data['github'] :
32
                (!empty($data['homepage']) ? $data['homepage'] : null);
33
            if ($history->hasLink($nick) || empty($href)) {
34
                continue;
35
            }
36
37
            if (!empty($data['email'])) {
38
                $history->unshiftLink($data['email'], $href);
39
            }
40
            $history->unshiftLink($nick, $href);
41 2
        }
42 2
    }
43
}
44