Completed
Push — master ( 065629...8bbaf2 )
by Andrii
03:11
created

ReleaseNotesRenderer::render()   A

Complexity

Conditions 3
Paths 2

Size

Total Lines 22
Code Lines 13

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 12

Importance

Changes 0
Metric Value
c 0
b 0
f 0
dl 0
loc 22
ccs 0
cts 17
cp 0
rs 9.2
cc 3
eloc 13
nc 2
nop 1
crap 12
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) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $hrefs of type array is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
49
            $result .= PHP_EOL . $this->renderLinks($hrefs);
50
        }
51
52
        return $result;
53
    }
54
}
55