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

TaskListItemMarkerRenderer::render()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 3

Importance

Changes 0
Metric Value
dl 0
loc 14
ccs 7
cts 7
cp 1
rs 9.7998
c 0
b 0
f 0
cc 3
nc 3
nop 2
crap 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