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

TableCaptionRenderer   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 100 %

Coupling/Cohesion

Components 0
Dependencies 3

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
c 1
b 0
f 1
lcom 0
cbo 3
dl 20
loc 20
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 17 17 4

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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