ListItemRenderer   A
last analyzed

Coupling/Cohesion

Components 0
Dependencies 4

Complexity

Total Complexity 5

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 0
cbo 4
dl 0
loc 33
ccs 16
cts 16
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B render() 0 23 5
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * Original code based on the CommonMark JS reference parser (https://bitly.com/commonmark-js)
9
 *  - (c) John MacFarlane
10
 *
11
 * For the full copyright and license information, please view the LICENSE
12
 * file that was distributed with this source code.
13
 */
14
15
namespace League\CommonMark\Block\Renderer;
16
17
use League\CommonMark\Block\Element\AbstractBlock;
18
use League\CommonMark\Block\Element\ListItem;
19
use League\CommonMark\ElementRendererInterface;
20
use League\CommonMark\HtmlElement;
21
use League\CommonMark\Util\Xml;
22
23
class ListItemRenderer implements BlockRendererInterface
24
{
25
    /**
26
     * @param ListItem                 $block
27
     * @param ElementRendererInterface $htmlRenderer
28
     * @param bool                     $inTightList
29
     *
30
     * @return string
31
     */
32 243
    public function render(AbstractBlock $block, ElementRendererInterface $htmlRenderer, $inTightList = false)
33
    {
34 243
        if (!($block instanceof ListItem)) {
35 3
            throw new \InvalidArgumentException('Incompatible block type: ' . get_class($block));
36
        }
37
38 240
        $contents = $htmlRenderer->renderBlocks($block->children(), $inTightList);
39 240
        if (substr($contents, 0, 1) === '<') {
40 129
            $contents = "\n" . $contents;
41 129
        }
42 240
        if (substr($contents, -1, 1) === '>') {
43 147
            $contents .= "\n";
44 147
        }
45
46 240
        $attrs = [];
47 240
        foreach ($block->getData('attributes', []) as $key => $value) {
48 3
            $attrs[$key] = Xml::escape($value, true);
49 240
        }
50
51 240
        $li = new HtmlElement('li', $attrs, $contents);
52
53 240
        return $li;
54
    }
55
}
56