1 | <?php |
||
22 | class SnakList extends ArrayObject implements Comparable, Hashable { |
||
23 | |||
24 | /** |
||
25 | * Maps snak hashes to their offsets. |
||
26 | * |
||
27 | * @var array [ snak hash (string) => snak offset (string|int) ] |
||
28 | */ |
||
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 | */ |
||
41 | public function __construct( $snaks = [] ) { |
||
50 | |||
51 | /** |
||
52 | * @since 0.1 |
||
53 | * |
||
54 | * @param string $snakHash |
||
55 | * |
||
56 | * @return boolean |
||
57 | */ |
||
58 | public function hasSnakHash( $snakHash ) { |
||
61 | |||
62 | /** |
||
63 | * @since 0.1 |
||
64 | * |
||
65 | * @param string $snakHash |
||
66 | */ |
||
67 | public function removeSnakHash( $snakHash ) { |
||
73 | |||
74 | /** |
||
75 | * @since 0.1 |
||
76 | * |
||
77 | * @param Snak $snak |
||
78 | * |
||
79 | * @return boolean Indicates if the snak was added or not. |
||
80 | */ |
||
81 | public function addSnak( Snak $snak ) { |
||
89 | |||
90 | /** |
||
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 | * |
||
113 | * @param string $snakHash |
||
114 | * |
||
115 | * @return Snak|bool |
||
116 | */ |
||
117 | public function getSnak( $snakHash ) { |
||
125 | |||
126 | /** |
||
127 | * @see Comparable::equals |
||
128 | * |
||
129 | * The comparison is done purely value based, ignoring the order of the elements in the array. |
||
130 | * |
||
131 | * @since 0.3 |
||
132 | * |
||
133 | * @param mixed $target |
||
134 | * |
||
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 | * |
||
153 | * @return string |
||
154 | */ |
||
155 | public function getHash() { |
||
159 | |||
160 | /** |
||
161 | * Groups snaks by property, and optionally orders them. |
||
162 | * |
||
163 | * @param string[] $order List of property ID strings to order by. Snaks with other properties |
||
164 | * will also be grouped, but put at the end, in the order each property appeared first in the |
||
165 | * original list. |
||
166 | * |
||
167 | * @since 0.5 |
||
168 | */ |
||
169 | public function orderByProperty( array $order = [] ) { |
||
189 | |||
190 | /** |
||
191 | * Finds a new offset for when appending an element. |
||
192 | * The base class does this, so it would be better to integrate, |
||
193 | * but there does not appear to be any way to do this... |
||
194 | * |
||
195 | * @return int |
||
196 | */ |
||
197 | private function getNewOffset() { |
||
204 | |||
205 | /** |
||
206 | * @see ArrayObject::offsetUnset |
||
207 | * |
||
208 | * @since 0.1 |
||
209 | * |
||
210 | * @param int|string $index |
||
211 | */ |
||
212 | public function offsetUnset( $index ) { |
||
224 | |||
225 | /** |
||
226 | * @see ArrayObject::append |
||
227 | * |
||
228 | * @param Snak $value |
||
229 | */ |
||
230 | public function append( $value ) { |
||
233 | |||
234 | /** |
||
235 | * @see ArrayObject::offsetSet() |
||
236 | * |
||
237 | * @param int|string $index |
||
238 | * @param Snak $value |
||
239 | */ |
||
240 | public function offsetSet( $index, $value ) { |
||
243 | |||
244 | /** |
||
245 | * Method that actually sets the element and holds |
||
246 | * all common code needed for set operations, including |
||
247 | * type checking and offset resolving. |
||
248 | * |
||
249 | * @param int|string $index |
||
250 | * @param Snak $value |
||
251 | * |
||
252 | * @throws InvalidArgumentException |
||
253 | */ |
||
254 | private function setElement( $index, $value ) { |
||
271 | |||
272 | /** |
||
273 | * @see Serializable::serialize |
||
274 | * |
||
275 | * @return string |
||
276 | */ |
||
277 | public function serialize() { |
||
283 | |||
284 | /** |
||
285 | * @see Serializable::unserialize |
||
286 | * |
||
287 | * @param string $serialized |
||
288 | */ |
||
289 | public function unserialize( $serialized ) { |
||
300 | |||
301 | /** |
||
302 | * Returns if the ArrayObject has no elements. |
||
303 | * |
||
304 | * @return bool |
||
305 | */ |
||
306 | public function isEmpty() { |
||
309 | |||
310 | } |
||
311 |
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.