DirCheckboxes::getEntry()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 4
c 1
b 0
f 0
dl 0
loc 7
ccs 5
cts 5
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace kalanis\kw_tree_controls\Controls;
4
5
6
use kalanis\kw_forms\Controls;
7
use kalanis\kw_forms\Interfaces\IMultiValue;
8
use kalanis\kw_templates\HtmlElement;
9
use kalanis\kw_tree\Essentials\FileNode;
10
use kalanis\kw_tree_controls\ControlNode;
11
12
13
/**
14
 * Class DirCheckboxes
15
 * @package kalanis\kw_tree_controls\Controls
16
 */
17
class DirCheckboxes extends ATreeControl implements IMultiValue
18
{
19
    use TMultiValue;
20
    use TSubEntry;
21
22
    protected string $templateLabel = '';
23
24
    /**
25
     * @param ControlNode[] $nodes
26
     * @return string
27
     */
28 1
    protected function fillEntries(array $nodes): string
29
    {
30 1
        $list = HtmlElement::init('ul');
31 1
        foreach ($nodes as $subNode) {
32 1
            $entry = $this->getEntry($subNode);
33 1
            $entry->addChild($this->fillEntries($subNode->getSubNodes()));
34 1
            $list->addChild($entry);
35
        }
36 1
        return strval($list);
37
    }
38
39 1
    protected function getEntry(ControlNode $node): HtmlElement
40
    {
41 1
        $entry = HtmlElement::init('li', ['class' => 'dir']);
42 1
        if ($childControl = $node->getControl()) {
43 1
            $entry->addChild($childControl);
44
        }
45 1
        return $entry;
46
    }
47
48 1
    protected function getInput(FileNode $node): Controls\AControl
49
    {
50 1
        $input = new Controls\Checkbox();
51 1
        $input->set($this->getKey(), $this->stringPath($node), $this->stringName($node));
52 1
        $this->inputs[] = $input;
53 1
        return $input;
54
    }
55
}
56