1 | <?php |
||
17 | trait ChildTrait |
||
18 | { |
||
19 | /** |
||
20 | * @var ElementStorage |
||
21 | */ |
||
22 | protected $child; |
||
23 | |||
24 | /** |
||
25 | * @inheritdoc |
||
26 | */ |
||
27 | 7 | public function getChild($name) |
|
42 | |||
43 | /** |
||
44 | * @inheritdoc |
||
45 | */ |
||
46 | 4 | public function getChildById($id) |
|
65 | |||
66 | /** |
||
67 | * @inheritdoc |
||
68 | */ |
||
69 | 53 | public function getFirstChild() |
|
70 | { |
||
71 | 53 | if (!$this->hasChild()) { |
|
72 | 1 | return null; |
|
73 | } |
||
74 | |||
75 | 53 | return $this->child[0]; |
|
76 | } |
||
77 | |||
78 | /** |
||
79 | * @inheritdoc |
||
80 | */ |
||
81 | 53 | public function hasChild() |
|
85 | |||
86 | /** |
||
87 | * @inheritdoc |
||
88 | */ |
||
89 | 2 | public function getChildren() |
|
93 | |||
94 | /** |
||
95 | * @inheritdoc |
||
96 | */ |
||
97 | 8 | public function getChildAtIndex($index) |
|
101 | |||
102 | /** |
||
103 | * @inheritdoc |
||
104 | */ |
||
105 | 9 | public function removeChild(ElementInterface $child) |
|
116 | } |
This check looks for methods that are used by a trait but not required by it.
To illustrate, let’s look at the following code example
The trait
Idable
provides a methodequalsId
that in turn relies on the methodgetId()
. If this method does not exist on a class mixing in this trait, the method will fail.Adding the
getId()
as an abstract method to the trait will make sure it is available.