1 | <?php |
||
24 | class SnakList extends ArrayObject implements Comparable, Hashable { |
||
25 | |||
26 | /** |
||
27 | 7 | * Maps snak hashes to their offsets. |
|
28 | 7 | * |
|
29 | * @var array [ snak hash (string) => snak offset (string|int) ] |
||
30 | */ |
||
31 | private $offsetHashes = []; |
||
32 | |||
33 | /** |
||
34 | * @var int |
||
35 | */ |
||
36 | private $indexOffset = 0; |
||
37 | |||
38 | /** |
||
39 | * @param Snak[]|Traversable $snaks |
||
40 | 3 | * |
|
41 | 3 | * @throws InvalidArgumentException |
|
42 | */ |
||
43 | public function __construct( $snaks = [] ) { |
||
52 | 5 | ||
53 | 5 | /** |
|
54 | * @since 0.1 |
||
55 | * |
||
56 | * @param string $snakHash |
||
57 | * |
||
58 | * @return boolean |
||
59 | */ |
||
60 | public function hasSnakHash( $snakHash ) { |
||
63 | |||
64 | 10 | /** |
|
65 | 10 | * @since 0.1 |
|
66 | * |
||
67 | * @param string $snakHash |
||
68 | */ |
||
69 | public function removeSnakHash( $snakHash ) { |
||
75 | |||
76 | /** |
||
77 | 11 | * @since 0.1 |
|
78 | 11 | * |
|
79 | * @param Snak $snak |
||
80 | * |
||
81 | * @return boolean Indicates if the snak was added or not. |
||
82 | */ |
||
83 | public function addSnak( Snak $snak ) { |
||
91 | |||
92 | /** |
||
93 | * @since 0.1 |
||
94 | * |
||
95 | * @param Snak $snak |
||
96 | * |
||
97 | * @return boolean |
||
98 | */ |
||
99 | public function hasSnak( Snak $snak ) { |
||
102 | |||
103 | /** |
||
104 | * @since 0.1 |
||
105 | * |
||
106 | * @param Snak $snak |
||
107 | */ |
||
108 | public function removeSnak( Snak $snak ) { |
||
111 | |||
112 | 7 | /** |
|
113 | 7 | * @since 0.1 |
|
114 | 7 | * |
|
115 | * @param string $snakHash |
||
116 | * |
||
117 | * @return Snak|bool |
||
118 | */ |
||
119 | public function getSnak( $snakHash ) { |
||
127 | |||
128 | 7 | /** |
|
129 | 6 | * @see Comparable::equals |
|
130 | 5 | * |
|
131 | 5 | * The comparison is done purely value based, ignoring the order of the elements in the array. |
|
132 | 5 | * |
|
133 | 7 | * @since 0.3 |
|
134 | 7 | * |
|
135 | * @param mixed $target |
||
136 | * |
||
137 | * @return bool |
||
138 | */ |
||
139 | 5 | public function equals( $target ) { |
|
147 | |||
148 | /** |
||
149 | * @see Hashable::getHash |
||
150 | * |
||
151 | * The hash is purely value based. Order of the elements in the array is not held into account. |
||
152 | 7 | * |
|
153 | 7 | * @since 0.1 |
|
154 | * |
||
155 | 7 | * @return string |
|
156 | */ |
||
157 | 5 | public function getHash() { |
|
161 | 5 | ||
162 | 7 | /** |
|
163 | * Groups snaks by property, and optionally orders them. |
||
164 | 7 | * |
|
165 | * @param string[] $order List of property ID strings to order by. Snaks with other properties |
||
166 | * will also be grouped, but put at the end, in the order each property appeared first in the |
||
167 | * original list. |
||
168 | * |
||
169 | * @since 0.5 |
||
170 | */ |
||
171 | public function orderByProperty( array $order = [] ) { |
||
191 | |||
192 | /** |
||
193 | * Finds a new offset for when appending an element. |
||
194 | * The base class does this, so it would be better to integrate, |
||
195 | * but there does not appear to be any way to do this... |
||
196 | * |
||
197 | * @return int |
||
198 | */ |
||
199 | private function getNewOffset() { |
||
206 | |||
207 | /** |
||
208 | * @see ArrayObject::offsetUnset |
||
209 | * |
||
210 | * @since 0.1 |
||
211 | * |
||
212 | * @param int|string $index |
||
213 | */ |
||
214 | public function offsetUnset( $index ) { |
||
226 | |||
227 | /** |
||
228 | * @see ArrayObject::append |
||
229 | * |
||
230 | * @param Snak $value |
||
231 | */ |
||
232 | public function append( $value ) { |
||
235 | |||
236 | /** |
||
237 | * @see ArrayObject::offsetSet() |
||
238 | * |
||
239 | * @param int|string $index |
||
240 | * @param Snak $value |
||
241 | */ |
||
242 | public function offsetSet( $index, $value ) { |
||
245 | |||
246 | /** |
||
247 | * Method that actually sets the element and holds |
||
248 | * all common code needed for set operations, including |
||
249 | * type checking and offset resolving. |
||
250 | * |
||
251 | * @param int|string $index |
||
252 | * @param Snak $value |
||
253 | * |
||
254 | * @throws InvalidArgumentException |
||
255 | */ |
||
256 | private function setElement( $index, $value ) { |
||
273 | |||
274 | /** |
||
275 | * @see Serializable::serialize |
||
276 | * |
||
277 | * @return string |
||
278 | */ |
||
279 | public function serialize() { |
||
282 | |||
283 | /** |
||
284 | * @see Serializable::unserialize |
||
285 | * |
||
286 | * @param string $serialized |
||
287 | */ |
||
288 | public function unserialize( $serialized ) { |
||
292 | |||
293 | /** |
||
294 | * @see https://wiki.php.net/rfc/custom_object_serialization |
||
295 | * |
||
296 | * @return array |
||
297 | */ |
||
298 | public function __serialize(): array { |
||
304 | |||
305 | /** |
||
306 | * @see https://wiki.php.net/rfc/custom_object_serialization |
||
307 | * |
||
308 | * @param array $data |
||
309 | */ |
||
310 | public function __unserialize( $data ) : void { |
||
319 | |||
320 | /** |
||
321 | * Returns if the ArrayObject has no elements. |
||
322 | * |
||
323 | * @return bool |
||
324 | */ |
||
325 | public function isEmpty() { |
||
328 | |||
329 | } |
||
330 |
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.