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