FileCheckboxes   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 21
c 1
b 0
f 0
dl 0
loc 41
ccs 19
cts 19
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A fillEntries() 0 13 4
A getEntry() 0 7 2
A getInput() 0 6 1
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 FileCheckboxes
15
 * @package kalanis\kw_tree_controls\Controls
16
 */
17
class FileCheckboxes 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
            if ($subNode->getNode() && $subNode->getNode()->isDir()) {
33 1
                $entry = $this->getSubEntry($subNode);
34 1
                $entry->addChild($this->fillEntries($subNode->getSubNodes()));
35 1
                $list->addChild($entry);
36
            } else {
37 1
                $list->addChild($this->getEntry($subNode));
38
            }
39
        }
40 1
        return strval($list);
41
    }
42
43 1
    protected function getEntry(ControlNode $node): HtmlElement
44
    {
45 1
        $entry = HtmlElement::init('li', ['class' => 'file']);
46 1
        if ($childControl = $node->getControl()) {
47 1
            $entry->addChild($childControl);
48
        }
49 1
        return $entry;
50
    }
51
52 1
    protected function getInput(FileNode $node): Controls\AControl
53
    {
54 1
        $input = new Controls\Checkbox();
55 1
        $input->set($this->getKey(), $this->stringPath($node), $this->stringName($node));
56 1
        $this->inputs[] = $input;
57 1
        return $input;
58
    }
59
}
60