TaskListItemMarkerRenderer   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 14
c 1
b 0
f 0
dl 0
loc 47
ccs 16
cts 16
cp 1
rs 10
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A render() 0 15 2
A getXmlTagName() 0 3 1
A getXmlAttributes() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file is part of the league/commonmark package.
7
 *
8
 * (c) Colin O'Dell <[email protected]>
9
 *
10
 * For the full copyright and license information, please view the LICENSE
11
 * file that was distributed with this source code.
12
 */
13
14
namespace League\CommonMark\Extension\TaskList;
15
16
use League\CommonMark\Node\Node;
17
use League\CommonMark\Renderer\ChildNodeRendererInterface;
18
use League\CommonMark\Renderer\NodeRendererInterface;
19
use League\CommonMark\Util\HtmlElement;
20
use League\CommonMark\Xml\XmlNodeRendererInterface;
21
22
final class TaskListItemMarkerRenderer implements NodeRendererInterface, XmlNodeRendererInterface
23
{
24
    /**
25
     * @param TaskListItemMarker $node
26
     *
27
     * {@inheritDoc}
28
     *
29
     * @psalm-suppress MoreSpecificImplementedParamType
30
     */
31 12
    public function render(Node $node, ChildNodeRendererInterface $childRenderer): \Stringable
32
    {
33 12
        TaskListItemMarker::assertInstanceOf($node);
34
35 10
        $attrs    = $node->data->get('attributes');
36 10
        $checkbox = new HtmlElement('input', $attrs, '', true);
37
38 10
        if ($node->isChecked()) {
39 8
            $checkbox->setAttribute('checked', '');
40
        }
41
42 10
        $checkbox->setAttribute('disabled', '');
43 10
        $checkbox->setAttribute('type', 'checkbox');
44
45 10
        return $checkbox;
46
    }
47
48 2
    public function getXmlTagName(Node $node): string
49
    {
50 2
        return 'task_list_item_marker';
51
    }
52
53
    /**
54
     * @param TaskListItemMarker $node
55
     *
56
     * @return array<string, scalar>
57
     *
58
     * @psalm-suppress MoreSpecificImplementedParamType
59
     */
60 2
    public function getXmlAttributes(Node $node): array
61
    {
62 2
        TaskListItemMarker::assertInstanceOf($node);
63
64 2
        if ($node->isChecked()) {
65 2
            return ['checked' => 'checked'];
66
        }
67
68 2
        return [];
69
    }
70
}
71