Completed
Push — master ( de5083...d66b3e )
by Martin
17:34
created

TableCellRenderer   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 24
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 81.82%

Importance

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

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
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
            if ($block->type == TableCell::TYPE_HEAD) {
36 4
                $attrs['style'] = "text-align: $block->align";
37
            } else {
38 4
                $attrs['align'] = $block->align;
39
            }
40
        }
41
42 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...
43
    }
44
}
45