Completed
Push — master ( 6894d9...a74f91 )
by Colin
02:02
created

TaskListItemMarkerRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 0
cbo 2
dl 0
loc 23
ccs 7
cts 7
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 14 3
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark-ext-task-list package.
5
 *
6
 * (c) Colin O'Dell <[email protected]>
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace League\CommonMark\Ext\TaskList;
13
14
use League\CommonMark\ElementRendererInterface;
15
use League\CommonMark\HtmlElement;
16
use League\CommonMark\Inline\Element\AbstractInline;
17
use League\CommonMark\Inline\Renderer\InlineRendererInterface;
18
19
final class TaskListItemMarkerRenderer implements InlineRendererInterface
20
{
21
    /**
22
     * @param AbstractInline           $inline
23
     * @param ElementRendererInterface $htmlRenderer
24
     *
25
     * @return HtmlElement|string|null
26
     */
27 12
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
28
    {
29 12
        if (!($inline instanceof TaskListItemMarker)) {
30 3
            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
31
        }
32
33 9
        $checkbox = new HtmlElement('input', ['disabled' => '', 'type' => 'checkbox'], '', true);
34
35 9
        if ($inline->isChecked()) {
36 6
            $checkbox->setAttribute('checked', '');
37
        }
38
39 9
        return $checkbox;
40
    }
41
}
42