Completed
Push — master ( d66b3e...4304b1 )
by Martin
05:01 queued 29s
created

TableCellRenderer::render()   B

Complexity

Conditions 5
Paths 7

Size

Total Lines 17
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 5.2742

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 17
ccs 7
cts 9
cp 0.7778
rs 8.8571
cc 5
eloc 9
nc 7
nop 3
crap 5.2742
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
use League\CommonMark\Util\Xml;
20
21
class TableCellRenderer implements BlockRendererInterface
22
{
23 17
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
24
    {
25 17
        if (!$block instanceof TableCell) {
26
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
27
        }
28
29 17
        $attrs = [];
30 17
        foreach ($block->getData('attributes', []) as $key => $value) {
31
            $attrs[$key] = Xml::escape($value, true);
32
        }
33
34 17
        if ($block->align) {
35 4
            $attrs['style'] = (isset($attrs['style']) ? $attrs['style'] . ' ' : '') . 'text-align: ' . $block->align;
36
        }
37
38 17
        return new HtmlElement($block->type, $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...
39
    }
40
}
41