Passed
Push — master ( 3af447...efa86f )
by Petr
10:22
created

TParent::afterParentSet()   A

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
    /** @var IHtmlElement|null */
20
    protected $parent;
21
22
    /**
23
     * Set parent element
24
     * @param IHtmlElement|null $parent
25
     */
26 3
    public function setParent(?IHtmlElement $parent = null): void
27
    {
28 3
        $this->parent = $parent;
29 3
        $this->afterParentSet();
30 3
    }
31
32
    /**
33
     * Returns parent element
34
     * @return IHtmlElement|null
35
     */
36 1
    public function getParent(): ?IHtmlElement
37
    {
38 1
        return $this->parent;
39
    }
40
41
    /**
42
     * Change element settings after new parent has been set
43
     */
44 3
    protected function afterParentSet(): void
45
    {
46 3
    }
47
48
    /**
49
     * Add $element after current one - if there is any parent
50
     * @param IHtmlElement|string $element
51
     * @param string $alias
52
     */
53 1
    public function append($element, ?string $alias = null): void
54
    {
55 1
        if ($this->parent instanceof IHtmlElement) {
56 1
            $this->parent->addChild($element, $alias);
57
        }
58 1
    }
59
}
60