1 | <?php |
||
17 | trait PropertiesPart { |
||
18 | |||
19 | /** @var Map|PhpProperty[] */ |
||
20 | private $properties; |
||
21 | |||
22 | 51 | private function initProperties() { |
|
25 | |||
26 | /** |
||
27 | * Sets a collection of properties |
||
28 | * |
||
29 | * @param PhpProperty[] $properties |
||
30 | * @return $this |
||
31 | */ |
||
32 | 1 | public function setProperties(array $properties) { |
|
45 | |||
46 | /** |
||
47 | * Adds a property |
||
48 | * |
||
49 | * @param PhpProperty $property |
||
50 | * @return $this |
||
51 | */ |
||
52 | 11 | public function addProperty(PhpProperty $property) { |
|
67 | |||
68 | /** |
||
69 | * Removes a property |
||
70 | * |
||
71 | * @param PhpProperty|string $nameOrProperty property name or instance |
||
72 | * @throws \InvalidArgumentException If the property cannot be found |
||
73 | * @return $this |
||
74 | */ |
||
75 | 2 | public function removeProperty($nameOrProperty) { |
|
89 | |||
90 | /** |
||
91 | * Checks whether a property exists |
||
92 | * |
||
93 | * @param PhpProperty|string $nameOrProperty property name or instance |
||
94 | * @return bool `true` if a property exists and `false` if not |
||
95 | */ |
||
96 | 1 | public function hasProperty($nameOrProperty): bool { |
|
103 | |||
104 | /** |
||
105 | * Returns a property |
||
106 | * |
||
107 | * @param string $nameOrProperty property name |
||
108 | * @throws \InvalidArgumentException If the property cannot be found |
||
109 | * @return PhpProperty |
||
110 | */ |
||
111 | 5 | public function getProperty($nameOrProperty): PhpProperty { |
|
122 | |||
123 | /** |
||
124 | * Returns a collection of properties |
||
125 | * |
||
126 | * @return Map|PhpProperty[] |
||
127 | */ |
||
128 | 15 | public function getProperties(): Map { |
|
131 | |||
132 | /** |
||
133 | * Returns all property names |
||
134 | * |
||
135 | * @return Set |
||
136 | */ |
||
137 | 1 | public function getPropertyNames(): Set { |
|
140 | |||
141 | /** |
||
142 | * Clears all properties |
||
143 | * |
||
144 | * @return $this |
||
145 | */ |
||
146 | 1 | public function clearProperties() { |
|
154 | } |
||
155 |
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.