TSubEntry::renderTree()   A
last analyzed

Complexity

Conditions 3
Paths 3

Size

Total Lines 15
Code Lines 11

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 12
CRAP Score 3

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 15
ccs 12
cts 12
cp 1
rs 9.9
cc 3
nc 3
nop 1
crap 3
1
<?php
2
3
namespace kalanis\kw_tree_controls\Controls;
4
5
6
use kalanis\kw_templates\HtmlElement;
7
use kalanis\kw_tree\Essentials\FileNode;
8
use kalanis\kw_tree_controls\ControlNode;
9
10
11
/**
12
 * Trait TSubEntry
13
 * @package kalanis\kw_tree_controls\Controls
14
 */
15
trait TSubEntry
16
{
17 4
    protected function renderTree(?ControlNode $baseNode): string
18
    {
19 4
        if (empty($baseNode)) {
20 4
            return '';
21
        }
22 4
        $fieldset = HtmlElement::init('fieldset');
23 4
        $legend = HtmlElement::init('legend');
24 4
        $div = HtmlElement::init('div', ['class' => 'select_tree']);
25 4
        if (!is_null($this->getLabel())) {
26 4
            $legend->addChild($this->getLabel());
27
        }
28 4
        $div->addChild($this->fillEntries([$baseNode]));
29 4
        $fieldset->addChild($legend);
30 4
        $fieldset->addChild($div);
31 4
        return $fieldset->render();
32
    }
33
34 2
    protected function getSubEntry(ControlNode $node): HtmlElement
35
    {
36 2
        $entry = HtmlElement::init('li', ['value' => $this->stringPath($node->getNode())]);
37 2
        $label = HtmlElement::init('label', ['class' => 'dir']);
38 2
        $label->addChild($this->stringName($node->getNode()));
39 2
        $entry->addChild($label);
40 2
        return $entry;
41
    }
42
43
    abstract public function getLabel(): ?string;
44
45
    abstract public function addChild($child, $alias = null, bool $merge = false, bool $inherit = false): void;
46
47
    abstract protected function fillEntries(array $nodes): string;
48
49
    abstract protected function stringName(?FileNode $node): string;
50
51
    abstract protected function stringPath(?FileNode $node): string;
52
}
53