Completed
Push — master ( 90d35b...b28524 )
by Andrii
05:54
created

AddAuthorLinks   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 0
cbo 3
dl 0
loc 25
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B run() 0 18 8
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
    public function run(History $history)
26
    {
27
        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
        }
42
    }
43
44
}
45