AppendageMaintainance   A
last analyzed

Complexity

Total Complexity 12

Size/Duplication

Total Lines 98
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 6
Bugs 4 Features 1
Metric Value
wmc 12
c 6
b 4
f 1
lcom 1
cbo 1
dl 0
loc 98
rs 10

7 Methods

Rating   Name   Duplication   Size   Complexity  
A addInheritableAppendage() 0 5 1
A leaveInheritableAppendage() 0 6 2
A storeInheritableAppendage() 0 12 4
A getInheritableAppendage() 0 7 2
A existsInheritableAppendage() 0 4 1
A appendageIsIndividual() 0 4 1
A getInheritableAppendages() 0 4 1
1
<?php
2
3
namespace hemio\html\Trait_;
4
5
/**
6
 *
7
 */
8
trait AppendageMaintainance
9
{
10
    /**
11
     * @var array
12
     */
13
    protected $arrInheritableAppendages = [];
14
15
    /**
16
     * List of appendages that are explicitly defined on this object. They
17
     * are not overwritten from appendages from object that are higher
18
     * in the hierarchy.
19
     *
20
     * @var array
21
     */
22
    protected $arrIndividualAppendages = [];
23
24
    /**
25
     *
26
     * @param string $key
27
     * @param mixed $appendage
28
     */
29
    public function addInheritableAppendage($key, $appendage)
30
    {
31
        $this->arrIndividualAppendages[$key] = true;
32
        $this->storeInheritableAppendage($key, $appendage);
33
    }
34
35
    /**
36
     *
37
     * @param string $key
38
     * @param mixed $appendage
39
     */
40
    public function leaveInheritableAppendage($key, $appendage)
41
    {
42
        if (!$this->appendageIsIndividual($key)) {
43
            $this->storeInheritableAppendage($key, $appendage);
44
        }
45
    }
46
47
    /**
48
     *
49
     * @param string $key
50
     * @param mixed $appendage
51
     */
52
    private function storeInheritableAppendage($key, $appendage)
53
    {
54
        $this->arrInheritableAppendages[$key] = $appendage;
55
56
        if ($this instanceof \hemio\html\Interface_\MaintainsChilds) {
57
            foreach ($this as $child) {
58
                if ($child instanceof \hemio\html\Interface_\MaintainsAppendages) {
59
                    $child->leaveInheritableAppendage($key, $appendage);
60
                }
61
            }
62
        }
63
    }
64
65
    /**
66
     *
67
     * @param string $key
68
     * @return null|mixed
69
     */
70
    public function getInheritableAppendage($key)
71
    {
72
        if (array_key_exists($key, $this->arrInheritableAppendages))
73
            return $this->arrInheritableAppendages[$key];
74
        else
75
            return null;
76
    }
77
78
    /**
79
     *
80
     * @param string $key
81
     * @return boolean
82
     */
83
    public function existsInheritableAppendage($key)
84
    {
85
        return $this->getInheritableAppendage($key) !== null;
86
    }
87
88
    /**
89
     *
90
     * @param string $key
91
     * @return boolean
92
     */
93
    public function appendageIsIndividual($key)
94
    {
95
        return array_key_exists($key, $this->arrIndividualAppendages);
96
    }
97
98
    /**
99
     * @return array All appendages with keys
100
     */
101
    public function getInheritableAppendages()
102
    {
103
        return $this->arrInheritableAppendages;
104
    }
105
}
106