1 | <?php |
||
20 | class SnakList extends ArrayObject { |
||
21 | |||
22 | /** |
||
23 | * Maps snak hashes to their offsets. |
||
24 | * |
||
25 | * @var array [ snak hash (string) => snak offset (string|int) ] |
||
26 | */ |
||
27 | 7 | private $offsetHashes = []; |
|
28 | 7 | ||
29 | /** |
||
30 | * @var int |
||
31 | */ |
||
32 | private $indexOffset = 0; |
||
33 | |||
34 | /** |
||
35 | * @param Snak[]|Traversable $snaks |
||
36 | * |
||
37 | * @throws InvalidArgumentException |
||
38 | */ |
||
39 | public function __construct( $snaks = [] ) { |
||
48 | |||
49 | /** |
||
50 | * @since 0.1 |
||
51 | 5 | * |
|
52 | 5 | * @param string $snakHash |
|
53 | 5 | * |
|
54 | * @return boolean |
||
55 | */ |
||
56 | public function hasSnakHash( $snakHash ) { |
||
59 | |||
60 | /** |
||
61 | * @since 0.1 |
||
62 | * |
||
63 | * @param string $snakHash |
||
64 | 10 | */ |
|
65 | 10 | public function removeSnakHash( $snakHash ) { |
|
71 | |||
72 | /** |
||
73 | * @since 0.1 |
||
74 | * |
||
75 | * @param Snak $snak |
||
76 | * |
||
77 | 11 | * @return boolean Indicates if the snak was added or not. |
|
78 | 11 | */ |
|
79 | public function addSnak( Snak $snak ) { |
||
87 | |||
88 | 13 | /** |
|
89 | 13 | * @since 0.1 |
|
90 | 13 | * |
|
91 | * @param Snak $snak |
||
92 | * |
||
93 | * @return boolean |
||
94 | */ |
||
95 | public function hasSnak( Snak $snak ) { |
||
98 | |||
99 | /** |
||
100 | * @since 0.1 |
||
101 | * |
||
102 | * @param Snak $snak |
||
103 | */ |
||
104 | public function removeSnak( Snak $snak ) { |
||
107 | |||
108 | /** |
||
109 | * @since 0.1 |
||
110 | * |
||
111 | * @param string $snakHash |
||
112 | 7 | * |
|
113 | 7 | * @return Snak|bool |
|
114 | 7 | */ |
|
115 | public function getSnak( $snakHash ) { |
||
123 | |||
124 | 7 | /** |
|
125 | 7 | * |
|
126 | 7 | * The comparison is done purely value based, ignoring the order of the elements in the array. |
|
127 | * |
||
128 | 7 | * @since 0.3 |
|
129 | 6 | * |
|
130 | 5 | * @param mixed $target |
|
131 | 5 | * |
|
132 | 5 | * @return bool |
|
133 | 7 | */ |
|
134 | 7 | public function equals( $target ) { |
|
142 | 5 | ||
143 | 5 | /** |
|
144 | 5 | * The hash is purely value based. Order of the elements in the array is not held into account. |
|
145 | * |
||
146 | * @since 0.1 |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getHash() { |
||
154 | |||
155 | 7 | /** |
|
156 | * Groups snaks by property, and optionally orders them. |
||
157 | 5 | * |
|
158 | 5 | * @param string[] $order List of property ID strings to order by. Snaks with other properties |
|
159 | 5 | * will also be grouped, but put at the end, in the order each property appeared first in the |
|
160 | 5 | * original list. |
|
161 | 5 | * |
|
162 | 7 | * @since 0.5 |
|
163 | */ |
||
164 | 7 | public function orderByProperty( array $order = [] ) { |
|
184 | |||
185 | /** |
||
186 | * Finds a new offset for when appending an element. |
||
187 | * The base class does this, so it would be better to integrate, |
||
188 | * but there does not appear to be any way to do this... |
||
189 | * |
||
190 | * @return int |
||
191 | */ |
||
192 | private function getNewOffset() { |
||
199 | |||
200 | /** |
||
201 | * @see ArrayObject::offsetUnset |
||
202 | * |
||
203 | * @since 0.1 |
||
204 | * |
||
205 | * @param int|string $index |
||
206 | */ |
||
207 | public function offsetUnset( $index ) { |
||
219 | |||
220 | /** |
||
221 | * @see ArrayObject::append |
||
222 | * |
||
223 | * @param Snak $value |
||
224 | */ |
||
225 | public function append( $value ) { |
||
228 | |||
229 | /** |
||
230 | * @see ArrayObject::offsetSet() |
||
231 | * |
||
232 | * @param int|string $index |
||
233 | * @param Snak $value |
||
234 | */ |
||
235 | public function offsetSet( $index, $value ) { |
||
238 | |||
239 | /** |
||
240 | * Method that actually sets the element and holds |
||
241 | * all common code needed for set operations, including |
||
242 | * type checking and offset resolving. |
||
243 | * |
||
244 | * @param int|string $index |
||
245 | * @param Snak $value |
||
246 | * |
||
247 | * @throws InvalidArgumentException |
||
248 | */ |
||
249 | private function setElement( $index, $value ) { |
||
266 | |||
267 | /** |
||
268 | * @see Serializable::serialize |
||
269 | * |
||
270 | * @return string |
||
271 | */ |
||
272 | public function serialize() { |
||
275 | |||
276 | /** |
||
277 | * @see Serializable::unserialize |
||
278 | * |
||
279 | * @param string $serialized |
||
280 | */ |
||
281 | public function unserialize( $serialized ) { |
||
285 | |||
286 | /** |
||
287 | * @see https://wiki.php.net/rfc/custom_object_serialization |
||
288 | * |
||
289 | * @return array |
||
290 | */ |
||
291 | public function __serialize(): array { |
||
297 | |||
298 | /** |
||
299 | * @see https://wiki.php.net/rfc/custom_object_serialization |
||
300 | * |
||
301 | * @param array $data |
||
302 | */ |
||
303 | public function __unserialize( $data ) : void { |
||
312 | |||
313 | /** |
||
314 | * Returns if the ArrayObject has no elements. |
||
315 | * |
||
316 | * @return bool |
||
317 | */ |
||
318 | public function isEmpty() { |
||
321 | |||
322 | } |
||
323 |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.