1
|
|
|
<?php |
2
|
|
|
/* |
3
|
|
|
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
4
|
|
|
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
5
|
|
|
* LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
6
|
|
|
* A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
7
|
|
|
* OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
8
|
|
|
* SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
9
|
|
|
* LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
10
|
|
|
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
11
|
|
|
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
12
|
|
|
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
13
|
|
|
* OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
14
|
|
|
* |
15
|
|
|
* This software consists of voluntary contributions made by many individuals |
16
|
|
|
* and is licensed under the MIT license. For more information, see |
17
|
|
|
* <http://www.doctrine-project.org>. |
18
|
|
|
*/ |
19
|
|
|
|
20
|
|
|
namespace Baleen\Migrations\Common\Collection; |
21
|
|
|
|
22
|
|
|
use Baleen\Migrations\Delta\Comparator\ComparatorInterface; |
23
|
|
|
use Baleen\Migrations\Delta\DeltaInterface; |
24
|
|
|
use Closure; |
25
|
|
|
use Countable; |
26
|
|
|
use IteratorAggregate; |
27
|
|
|
|
28
|
|
|
/** |
29
|
|
|
* Interface CollectionInterface. |
30
|
|
|
* |
31
|
|
|
* Based on the Doctrine\CollectionAbstract project. |
32
|
|
|
* |
33
|
|
|
* @see https://github.com/doctrine/collections |
34
|
|
|
* |
35
|
|
|
* @author Gabriel Somoza <[email protected]> |
36
|
|
|
*/ |
37
|
|
|
interface CollectionInterface extends Countable, IteratorAggregate |
38
|
|
|
{ |
39
|
|
|
/** |
40
|
|
|
* Adds an element at the end of the collection. |
41
|
|
|
* |
42
|
|
|
* @param DeltaInterface $element The element to add. |
43
|
|
|
* |
44
|
|
|
* @return boolean Always TRUE. |
45
|
|
|
*/ |
46
|
|
|
public function add(DeltaInterface $element); |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* Clears the collection, removing all elements. |
50
|
|
|
* |
51
|
|
|
* @return void |
52
|
|
|
*/ |
53
|
|
|
public function clear(); |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* Checks whether the collection contains an element with the specified key/index. |
57
|
|
|
* |
58
|
|
|
* @param string|integer $key The key/index to check for. |
59
|
|
|
* |
60
|
|
|
* @return bool TRUE if the collection contains an element with the specified key/index, |
61
|
|
|
* FALSE otherwise. |
62
|
|
|
*/ |
63
|
|
|
public function contains($key); |
64
|
|
|
|
65
|
|
|
/** |
66
|
|
|
* Checks whether the collection contains a version with the same id as the one specified |
67
|
|
|
* |
68
|
|
|
* @param DeltaInterface $version |
69
|
|
|
* |
70
|
|
|
* @return bool |
71
|
|
|
*/ |
72
|
|
|
public function containsVersion(DeltaInterface $version); |
73
|
|
|
|
74
|
|
|
/** |
75
|
|
|
* Checks whether the collection is empty (contains no elements). |
76
|
|
|
* |
77
|
|
|
* @return boolean TRUE if the collection is empty, FALSE otherwise. |
78
|
|
|
*/ |
79
|
|
|
public function isEmpty(); |
80
|
|
|
|
81
|
|
|
/** |
82
|
|
|
* Removes the element at the specified index from the collection. |
83
|
|
|
* |
84
|
|
|
* @param string|integer $key The kex/index of the element to remove. |
85
|
|
|
* |
86
|
|
|
* @return mixed The removed element or NULL, if the collection did not contain the element. |
87
|
|
|
*/ |
88
|
|
|
public function remove($key); |
89
|
|
|
|
90
|
|
|
/** |
91
|
|
|
* Gets the element at the specified key/index. |
92
|
|
|
* |
93
|
|
|
* @param string|integer $key The key/index of the element to retrieve. |
94
|
|
|
* |
95
|
|
|
* @return DeltaInterface|null |
96
|
|
|
*/ |
97
|
|
|
public function get($key); |
98
|
|
|
|
99
|
|
|
/** |
100
|
|
|
* Gets all keys/indices of the collection. |
101
|
|
|
* |
102
|
|
|
* @return array The keys/indices of the collection, in the order of the corresponding |
103
|
|
|
* elements in the collection. |
104
|
|
|
*/ |
105
|
|
|
public function getKeys(); |
106
|
|
|
|
107
|
|
|
/** |
108
|
|
|
* Gets all values of the collection. |
109
|
|
|
* |
110
|
|
|
* @return DeltaInterface[] The values of all elements in the collection, in the order they appear in the |
111
|
|
|
* collection. |
112
|
|
|
*/ |
113
|
|
|
public function getValues(); |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* Gets a native PHP array representation of the collection. |
117
|
|
|
* |
118
|
|
|
* @return DeltaInterface[] |
119
|
|
|
*/ |
120
|
|
|
public function toArray(); |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* Sets the internal iterator to the first element in the collection and returns this element. |
124
|
|
|
* |
125
|
|
|
* @return DeltaInterface |
126
|
|
|
*/ |
127
|
|
|
public function first(); |
128
|
|
|
|
129
|
|
|
/** |
130
|
|
|
* Sets the internal iterator to the last element in the collection and returns this element. |
131
|
|
|
* |
132
|
|
|
* @return DeltaInterface |
133
|
|
|
*/ |
134
|
|
|
public function last(); |
135
|
|
|
|
136
|
|
|
/** |
137
|
|
|
* Gets the key/index of the element at the current iterator getPosition. |
138
|
|
|
* |
139
|
|
|
* @return int|string |
140
|
|
|
*/ |
141
|
|
|
public function key(); |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* Gets the element of the collection at the current iterator getPosition. |
145
|
|
|
* |
146
|
|
|
* @return DeltaInterface |
147
|
|
|
*/ |
148
|
|
|
public function current(); |
149
|
|
|
|
150
|
|
|
/** |
151
|
|
|
* Moves the internal iterator getPosition to the next element and returns this element. |
152
|
|
|
* |
153
|
|
|
* @return DeltaInterface |
154
|
|
|
*/ |
155
|
|
|
public function next(); |
156
|
|
|
|
157
|
|
|
/** |
158
|
|
|
* Tests for the existence of an element that satisfies the given predicate. |
159
|
|
|
* |
160
|
|
|
* @param Closure $p The predicate. |
161
|
|
|
* |
162
|
|
|
* @return boolean TRUE if the predicate is TRUE for at least one element, FALSE otherwise. |
163
|
|
|
*/ |
164
|
|
|
public function exists(Closure $p); |
165
|
|
|
|
166
|
|
|
/** |
167
|
|
|
* Returns all the elements of this collection that satisfy the predicate p. |
168
|
|
|
* The order of the elements is preserved. |
169
|
|
|
* |
170
|
|
|
* @param Closure $p The predicate used for filtering. |
171
|
|
|
* |
172
|
|
|
* @return CollectionInterface A collection with the results of the filter operation. |
173
|
|
|
*/ |
174
|
|
|
public function filter(Closure $p); |
175
|
|
|
|
176
|
|
|
/** |
177
|
|
|
* Tests whether the given predicate p holds for all elements of this collection. |
178
|
|
|
* |
179
|
|
|
* @param Closure $p The predicate. |
180
|
|
|
* |
181
|
|
|
* @return boolean TRUE, if the predicate yields TRUE for all elements, FALSE otherwise. |
182
|
|
|
*/ |
183
|
|
|
public function forAll(Closure $p); |
184
|
|
|
|
185
|
|
|
/** |
186
|
|
|
* Applies the given function to each element in the collection and returns |
187
|
|
|
* a new collection with the elements returned by the function. |
188
|
|
|
* |
189
|
|
|
* @param Closure $func |
190
|
|
|
* |
191
|
|
|
* @return array |
192
|
|
|
*/ |
193
|
|
|
public function map(Closure $func); |
194
|
|
|
|
195
|
|
|
/** |
196
|
|
|
* Partitions this collection in two collections according to a predicate. |
197
|
|
|
* Keys are preserved in the resulting collections. |
198
|
|
|
* |
199
|
|
|
* @param Closure $p The predicate on which to partition. |
200
|
|
|
* |
201
|
|
|
* @return CollectionInterface[] An array with two elements. The first element contains the collection |
202
|
|
|
* of elements where the predicate returned TRUE, the second element |
203
|
|
|
* contains the collection of elements where the predicate returned FALSE. |
204
|
|
|
*/ |
205
|
|
|
public function partition(Closure $p); |
206
|
|
|
|
207
|
|
|
/** |
208
|
|
|
* Extracts a slice of $length elements starting at getPosition $offset from the CollectionAbstract. |
209
|
|
|
* |
210
|
|
|
* If $length is null it returns all elements from $offset to the end of the CollectionAbstract. |
211
|
|
|
* Keys have to be preserved by this method. Calling this method will only return the |
212
|
|
|
* selected slice and NOT change the elements contained in the collection slice is called on. |
213
|
|
|
* |
214
|
|
|
* @param int $offset The offset to start from. |
215
|
|
|
* @param int|null $length The maximum number of elements to return, or null for no limit. |
216
|
|
|
* |
217
|
|
|
* @return array |
218
|
|
|
*/ |
219
|
|
|
public function slice($offset, $length = null); |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* Replaces a version in-place with the specified version. |
223
|
|
|
* |
224
|
|
|
* @param DeltaInterface $version |
225
|
|
|
* |
226
|
|
|
* @return DeltaInterface|null The replaced element or NULL, if the collection didn't contain the element. |
227
|
|
|
*/ |
228
|
|
|
public function replace(DeltaInterface $version); |
229
|
|
|
|
230
|
|
|
/** |
231
|
|
|
* Returns the ordinal getPosition of the item in the array. |
232
|
|
|
* |
233
|
|
|
* @param string $key |
234
|
|
|
* |
235
|
|
|
* @return int |
236
|
|
|
*/ |
237
|
|
|
public function getPosition($key); |
238
|
|
|
|
239
|
|
|
/** |
240
|
|
|
* Returns the element at the given ordinal getPosition. |
241
|
|
|
* |
242
|
|
|
* @param int $position |
243
|
|
|
* |
244
|
|
|
* @return null|DeltaInterface |
245
|
|
|
*/ |
246
|
|
|
public function getByPosition($position); |
247
|
|
|
|
248
|
|
|
/** |
249
|
|
|
* Sort the collection |
250
|
|
|
* |
251
|
|
|
* @param ComparatorInterface $comparator |
|
|
|
|
252
|
|
|
* |
253
|
|
|
* @return CollectionInterface |
254
|
|
|
*/ |
255
|
|
|
public function sort(ComparatorInterface $comparator = null); |
256
|
|
|
|
257
|
|
|
/** |
258
|
|
|
* Returns a collection with elements sorted in reverse order. |
259
|
|
|
* |
260
|
|
|
* @return CollectionInterface |
261
|
|
|
*/ |
262
|
|
|
public function getReverse(); |
263
|
|
|
|
264
|
|
|
/** |
265
|
|
|
* @return ComparatorInterface |
266
|
|
|
*/ |
267
|
|
|
public function getComparator(); |
268
|
|
|
|
269
|
|
|
/** |
270
|
|
|
* Merges another set into this one, replacing versions that exist and adding those that don't. |
271
|
|
|
* |
272
|
|
|
* @param CollectionInterface $collection |
273
|
|
|
* |
274
|
|
|
* @return static |
275
|
|
|
*/ |
276
|
|
|
public function merge(CollectionInterface $collection); |
277
|
|
|
|
278
|
|
|
/** |
279
|
|
|
* Returns true if the specified version is valid (can be added) to the collection. Otherwise, it MUST throw |
280
|
|
|
* an exception. |
281
|
|
|
* |
282
|
|
|
* @param DeltaInterface $version |
283
|
|
|
* |
284
|
|
|
* @return bool |
285
|
|
|
*/ |
286
|
|
|
public function validate(DeltaInterface $version); |
287
|
|
|
} |
288
|
|
|
|
This check looks for
@param
annotations where the type inferred by our type inference engine differs from the declared type.It makes a suggestion as to what type it considers more descriptive.
Most often this is a case of a parameter that can be null in addition to its declared types.