AsideRenderer::render()   A
last analyzed

Complexity

Conditions 4
Paths 5

Size

Total Lines 22

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 4.7999

Importance

Changes 0
Metric Value
dl 0
loc 22
ccs 12
cts 19
cp 0.6316
rs 9.568
c 0
b 0
f 0
cc 4
nc 5
nop 3
crap 4.7999
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Davey Shafik <[email protected]>
7
 * (c) Colin O'Dell <[email protected]>
8
 * (c) Dan Hunsaker <[email protected]>
9
 *
10
 * Original code based on the CommonMark JS reference parser (http://bitly.com/commonmarkjs)
11
 *  - (c) John MacFarlane
12
 *
13
 * For the full copyright and license information, please view the LICENSE
14
 * file that was distributed with this source code.
15
 */
16
17
namespace Danhunsaker\Markua\Block\Renderer;
18
19
use League\CommonMark\Block\Element\AbstractBlock;
20
use League\CommonMark\Block\Renderer\BlockRendererInterface;
21
use League\CommonMark\HtmlElement;
22
use League\CommonMark\ElementRendererInterface;
23
use League\CommonMark\Util\Xml;
24
use Danhunsaker\Markua\Block\Element\Aside;
25
26
class AsideRenderer implements BlockRendererInterface
27
{
28
    /**
29
     * @param Aside                    $block
30
     * @param ElementRendererInterface $htmlRenderer
31
     * @param bool                     $inTightList
32
     *
33
     * @return HtmlElement
34
     */
35 30
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
36
    {
37 30
        if (!($block instanceof Aside)) {
38
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
39
        }
40
41 30
        $attrs = [];
42 30
        foreach ($block->getData('attributes', []) as $key => $value) {
43
            $attrs[$key] = Xml::escape($value, true);
44 30
        }
45
46 30
        $filling = $htmlRenderer->renderBlocks($block->children());
0 ignored issues
show
Documentation introduced by
$block->children() is of type array<integer,object<Lea...\CommonMark\Node\Node>>, but the function expects a array<integer,object<Lea...Element\AbstractBlock>>.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
47 30
        if ($filling === '') {
48
            return new HtmlElement('aside', $attrs, $htmlRenderer->getOption('inner_separator', "\n"));
49
        }
50
51 30
        return new HtmlElement(
52 30
            'aside',
53 30
            $attrs,
54 30
            $htmlRenderer->getOption('inner_separator', "\n") . $filling . $htmlRenderer->getOption('inner_separator', "\n")
55 30
        );
56
    }
57
}
58