Completed
Push — master ( e1e275...3d6629 )
by Martin
20:32
created

TableCaptionRenderer::render()   A

Complexity

Conditions 4
Paths 5

Size

Total Lines 17
Code Lines 9

Duplication

Lines 17
Ratio 100 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
c 1
b 0
f 1
dl 17
loc 17
rs 9.2
cc 4
eloc 9
nc 5
nop 3
1
<?php
2
3
/*
4
 * This is part of the webuni/commonmark-table-extension package.
5
 *
6
 * (c) Martin Hasoň <[email protected]>
7
 * (c) Webuni s.r.o. <[email protected]>
8
 *
9
 * For the full copyright and license information, please view the LICENSE
10
 * file that was distributed with this source code.
11
 */
12
13
namespace Webuni\CommonMark\TableExtension;
14
15
use League\CommonMark\Block\Element\AbstractBlock;
16
use League\CommonMark\Block\Renderer\BlockRendererInterface;
17
use League\CommonMark\ElementRendererInterface;
18
use League\CommonMark\HtmlElement;
19
20 View Code Duplication
class TableCaptionRenderer implements BlockRendererInterface
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
21
{
22
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
23
    {
24
        if (!($block instanceof TableCaption)) {
25
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
26
        }
27
28
        $attrs = [];
29
        foreach ($block->getData('attributes', []) as $key => $value) {
30
            $attrs[$key] = $htmlRenderer->escape($value, true);
31
        }
32
33
        if ($block->id) {
34
            $attrs['id'] = $block->id;
35
        }
36
37
        return new HtmlElement('caption', $attrs, $htmlRenderer->renderInlines($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...lement\AbstractInline>>.

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...
38
    }
39
}
40