TParent::afterParentSet()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 0
c 2
b 0
f 0
dl 0
loc 2
ccs 1
cts 1
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace kalanis\kw_templates\HtmlElement;
4
5
6
use kalanis\kw_templates\Interfaces\IHtmlElement;
7
8
9
/**
10
 * Trait TParent
11
 * @package kalanis\kw_templates\Template
12
 * Trait for work with parenting of html elements
13
 * Extend child of AHtmlElement
14
 * @author Adam Dornak original
15
 * @author Petr Plsek refactored
16
 */
17
trait TParent
18
{
19
    protected ?IHtmlElement $parent = null;
20
21
    /**
22
     * Set parent element
23
     * @param IHtmlElement|null $parent
24
     */
25 3
    public function setParent(?IHtmlElement $parent = null): void
26
    {
27 3
        $this->parent = $parent;
28 3
        $this->afterParentSet();
29 3
    }
30
31
    /**
32
     * Returns parent element
33
     * @return IHtmlElement|null
34
     */
35 1
    public function getParent(): ?IHtmlElement
36
    {
37 1
        return $this->parent;
38
    }
39
40
    /**
41
     * Change element settings after new parent has been set
42
     */
43 3
    protected function afterParentSet(): void
44
    {
45 3
    }
46
47
    /**
48
     * Add $element after current one - if there is any parent
49
     * @param IHtmlElement|string $element
50
     * @param string $alias
51
     */
52 1
    public function append($element, ?string $alias = null): void
53
    {
54 1
        if ($this->parent instanceof IHtmlElement) {
55 1
            $this->parent->addChild($element, $alias);
56
        }
57 1
    }
58
}
59