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

AddAuthorLinks::run()   B

Complexity

Conditions 8
Paths 25

Size

Total Lines 18
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 18
rs 7.7777
cc 8
eloc 11
nc 25
nop 1
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