Completed
Push — master ( 8d38b3...065629 )
by Andrii
02:12
created

NotesRenderer::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 NotesRenderer extends MarkdownRenderer
21
{
22
    /**
23
     * {@inheritdoc}
24
     */
25
    public function render(History $history)
26
    {
27
        $this->setHistory($history);
28
29
        $links = $history->getLinks();
30
        $hrefs = [];
31
        $result = $this->renderObjects('renderNote', $history->getFirstTag()->getNotes());
32
33
        $result = preg_replace_callback('/\[(\S*?)\]/', function ($matches) use ($links, &$hrefs) {
34
            if (isset($links[$matches[1]])) {
35
                $hrefs[$matches[1]] = $links[$matches[1]];
36
            }
37
38
            return $matches[0];
39
        }, $result);
40
41
        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...
42
            $result .= PHP_EOL . $this->renderLinks($hrefs);
43
        }
44
45
        return $result;
46
    }
47
}
48