ReleaseNotesRenderer   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 33
ccs 0
cts 16
cp 0
rs 10
c 1
b 0
f 0
wmc 3

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 21 3
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\changelog;
12
13
use hiqdev\chkipper\lib\History;
14
15
/**
16
 * Release Notes renderer.
17
 *
18
 * @author Andrii Vasyliev <[email protected]>
19
 */
20
class ReleaseNotesRenderer extends MarkdownRenderer
21
{
22
    protected $normalization = [
23
        'modifiers' => [
24
            'PrettifyUserLinks' => [],
25
            'RemoveEmptyFirstTag' => [],
26
        ],
27
    ];
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function render(History $history)
33
    {
34
        $this->setHistory($history);
35
36
        $links = $history->getLinks();
37
        $hrefs = [];
38
        $result = $this->renderObjects('renderNote', $history->getFirstTag()->getNotes());
39
40
        $result = preg_replace_callback('/\[(.*?)\]/', function ($matches) use ($links, &$hrefs) {
41
            if (isset($links[$matches[1]])) {
42
                $hrefs[$matches[1]] = $links[$matches[1]];
43
            }
44
45
            return $matches[0];
46
        }, $result);
47
48
        if ($hrefs) {
49
            $result .= PHP_EOL . $this->renderLinks($hrefs);
50
        }
51
52
        return $result;
53
    }
54
}
55