Completed
Push — master ( 83739a...a13ee4 )
by Colin
14s queued 11s
created

TaskListItemMarkerRenderer   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
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 26
ccs 9
cts 9
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
A render() 0 17 3
1
<?php
2
3
/*
4
 * This file is part of the league/commonmark 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\Extension\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 18
    public function render(AbstractInline $inline, ElementRendererInterface $htmlRenderer)
28
    {
29 18
        if (!($inline instanceof TaskListItemMarker)) {
30 3
            throw new \InvalidArgumentException('Incompatible inline type: ' . \get_class($inline));
31
        }
32
33 15
        $checkbox = new HtmlElement('input', [], '', true);
34
35 15
        if ($inline->isChecked()) {
36 12
            $checkbox->setAttribute('checked', '');
37
        }
38
39 15
        $checkbox->setAttribute('disabled', '');
40 15
        $checkbox->setAttribute('type', 'checkbox');
41
42 15
        return $checkbox;
43
    }
44
}
45