FileRadio::getInput()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 1

Importance

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