Completed
Pull Request — master (#11)
by
unknown
04:31
created

TableCellRenderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 3

Test Coverage

Coverage 81.82%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 3
dl 0
loc 24
ccs 9
cts 11
cp 0.8182
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 21 5
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
class TableCellRenderer implements BlockRendererInterface
21
{
22 16
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
23
    {
24 16
        if (!($block instanceof TableCell)) {
25
            throw new \InvalidArgumentException('Incompatible block type: '.get_class($block));
26
        }
27
28 16
        $attrs = [];
29 16
        foreach ($block->getData('attributes', []) as $key => $value) {
30
            $attrs[$key] = $htmlRenderer->escape($value, true);
31
        }
32
33 16
        if ($block->align) {
34 4
            if ($block->type == TableCell::TYPE_HEAD) {
35 4
                $attrs['style'] = "text-align: $block->align";
36
            } else {
37 4
                $attrs['align'] = $block->align;
38
            }
39
        }
40
41 16
        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...
42
    }
43
}
44