1 | <?php |
||
22 | class SnakList extends ArrayObject implements Comparable, Hashable { |
||
23 | |||
24 | /** |
||
25 | * Maps snak hashes to their offsets. |
||
26 | * |
||
27 | 7 | * @var array [ snak hash (string) => snak offset (string|int) ] |
|
28 | 7 | */ |
|
29 | private $offsetHashes = []; |
||
30 | |||
31 | /** |
||
32 | * @var int |
||
33 | */ |
||
34 | private $indexOffset = 0; |
||
35 | |||
36 | /** |
||
37 | * @param Snak[]|Traversable $snaks |
||
38 | * |
||
39 | * @throws InvalidArgumentException |
||
40 | 3 | */ |
|
41 | 3 | public function __construct( $snaks = [] ) { |
|
50 | |||
51 | 5 | /** |
|
52 | 5 | * @since 0.1 |
|
53 | 5 | * |
|
54 | * @param string $snakHash |
||
55 | * |
||
56 | * @return boolean |
||
57 | */ |
||
58 | public function hasSnakHash( $snakHash ) { |
||
61 | |||
62 | /** |
||
63 | * @since 0.1 |
||
64 | 10 | * |
|
65 | 10 | * @param string $snakHash |
|
66 | */ |
||
67 | public function removeSnakHash( $snakHash ) { |
||
73 | |||
74 | /** |
||
75 | * @since 0.1 |
||
76 | * |
||
77 | 11 | * @param Snak $snak |
|
78 | 11 | * |
|
79 | * @return boolean Indicates if the snak was added or not. |
||
80 | */ |
||
81 | public function addSnak( Snak $snak ) { |
||
89 | 13 | ||
90 | 13 | /** |
|
91 | * @since 0.1 |
||
92 | * |
||
93 | * @param Snak $snak |
||
94 | * |
||
95 | * @return boolean |
||
96 | */ |
||
97 | public function hasSnak( Snak $snak ) { |
||
100 | |||
101 | /** |
||
102 | * @since 0.1 |
||
103 | * |
||
104 | * @param Snak $snak |
||
105 | */ |
||
106 | public function removeSnak( Snak $snak ) { |
||
109 | |||
110 | /** |
||
111 | * @since 0.1 |
||
112 | 7 | * |
|
113 | 7 | * @param string $snakHash |
|
114 | 7 | * |
|
115 | * @return Snak|bool |
||
116 | */ |
||
117 | public function getSnak( $snakHash ) { |
||
125 | 7 | ||
126 | 7 | /** |
|
127 | * @see Comparable::equals |
||
128 | 7 | * |
|
129 | 6 | * The comparison is done purely value based, ignoring the order of the elements in the array. |
|
130 | 5 | * |
|
131 | 5 | * @since 0.3 |
|
132 | 5 | * |
|
133 | 7 | * @param mixed $target |
|
134 | 7 | * |
|
135 | * @return bool |
||
136 | */ |
||
137 | public function equals( $target ) { |
||
145 | |||
146 | /** |
||
147 | * @see Hashable::getHash |
||
148 | * |
||
149 | * The hash is purely value based. Order of the elements in the array is not held into account. |
||
150 | * |
||
151 | * @since 0.1 |
||
152 | 7 | * |
|
153 | 7 | * @return string |
|
154 | */ |
||
155 | 7 | public function getHash() { |
|
159 | 5 | ||
160 | 5 | /** |
|
161 | 5 | * Orders the snaks in the list grouping them by property. |
|
162 | 7 | * |
|
163 | * @param string[] $order List of serliazed property ids to order by. |
||
164 | 7 | * |
|
165 | * @since 0.5 |
||
166 | */ |
||
167 | public function orderByProperty( array $order = [] ) { |
||
178 | |||
179 | /** |
||
180 | * @param Snak[] $snaks to remove and re add |
||
181 | */ |
||
182 | private function moveSnaksToBottom( array $snaks ) { |
||
188 | |||
189 | /** |
||
190 | * Gets the snaks in the current object in an array |
||
191 | * grouped by property id |
||
192 | * |
||
193 | * @return array[] |
||
194 | */ |
||
195 | private function getSnaksByProperty() { |
||
209 | |||
210 | /** |
||
211 | * Finds a new offset for when appending an element. |
||
212 | * The base class does this, so it would be better to integrate, |
||
213 | * but there does not appear to be any way to do this... |
||
214 | * |
||
215 | * @return int |
||
216 | */ |
||
217 | private function getNewOffset() { |
||
224 | |||
225 | /** |
||
226 | * @see ArrayObject::offsetUnset |
||
227 | * |
||
228 | * @since 0.1 |
||
229 | * |
||
230 | * @param int|string $index |
||
231 | */ |
||
232 | public function offsetUnset( $index ) { |
||
244 | |||
245 | /** |
||
246 | * @see ArrayObject::append |
||
247 | * |
||
248 | * @param Snak $value |
||
249 | */ |
||
250 | public function append( $value ) { |
||
253 | |||
254 | /** |
||
255 | * @see ArrayObject::offsetSet() |
||
256 | * |
||
257 | * @param int|string $index |
||
258 | * @param Snak $value |
||
259 | */ |
||
260 | public function offsetSet( $index, $value ) { |
||
263 | |||
264 | /** |
||
265 | * Method that actually sets the element and holds |
||
266 | * all common code needed for set operations, including |
||
267 | * type checking and offset resolving. |
||
268 | * |
||
269 | * @param int|string $index |
||
270 | * @param Snak $value |
||
271 | * |
||
272 | * @throws InvalidArgumentException |
||
273 | */ |
||
274 | private function setElement( $index, $value ) { |
||
291 | |||
292 | /** |
||
293 | * @see Serializable::serialize |
||
294 | * |
||
295 | * @return string |
||
296 | */ |
||
297 | public function serialize() { |
||
303 | |||
304 | /** |
||
305 | * @see Serializable::unserialize |
||
306 | * |
||
307 | * @param string $serialized |
||
308 | */ |
||
309 | public function unserialize( $serialized ) { |
||
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.