Completed
Pull Request — master (#16)
by James
03:39
created
src/Contract/Axolotl/Collection.php 2 patches
Indentation   +314 added lines, -314 removed lines patch added patch discarded remove patch
@@ -9,318 +9,318 @@
 block discarded – undo
9 9
 
10 10
 interface Collection extends Iterator, Countable, Serializes {
11 11
 
12
-	/**
13
-	 * Returns the type of the collection.
14
-	 *
15
-	 * @return string
16
-	 */
17
-	public function get_type();
18
-
19
-	/**
20
-	 * Returns a collection with $element added.
21
-	 *
22
-	 * @param  mixed $element
23
-	 * @return Collection
24
-	 * @throws InvalidArgumentException
25
-	 */
26
-	public function add( $element );
27
-
28
-	/**
29
-	 * Removes every element from the collection.
30
-	 *
31
-	 * @return Collection
32
-	 */
33
-	public function clear();
34
-
35
-	/**
36
-	 * Returns true if the collection contains any elements that satisfy
37
-	 * $condition, returns false if it contains none.
38
-	 *
39
-	 * @param callable $condition
40
-	 * @return bool
41
-	 */
42
-	public function contains( $condition );
43
-
44
-	/**
45
-	 * Returns the first element in the collection that satisfies
46
-	 * $condition, returns false if no such element exists.
47
-	 *
48
-	 * @param callable $condition
49
-	 * @return mixed
50
-	 */
51
-	public function find( $condition );
52
-
53
-	/**
54
-	 * Returns the index of the first element in the collection that satisfies
55
-	 * $condition, returns -1 if no such element exists.
56
-	 *
57
-	 * @param callable $condition
58
-	 * @return int
59
-	 */
60
-	public function find_index( $condition );
61
-
62
-	/**
63
-	 * Returns the element in the collection at $index.
64
-	 *
65
-	 * @param  int $index Index to get element from.
66
-	 * @return mixed
67
-	 * @throws OutOfRangeException
68
-	 */
69
-	public function at( $index );
70
-
71
-	/**
72
-	 * Returns true if $index is within the collection's range and returns false
73
-	 * if it is not.
74
-	 *
75
-	 * @param  int $index Index to check for existence.
76
-	 * @return bool
77
-	 * @throws InvalidArgumentException
78
-	 */
79
-	public function index_exists( $index );
80
-
81
-	/**
82
-	 * Returns the number of elements in the collection.
83
-	 *
84
-	 * @return int
85
-	 */
86
-	public function count();
87
-
88
-	/**
89
-	 * Returns a collection that only contains the elements which satisfy
90
-	 * $condition.
91
-	 *
92
-	 * @param callable $condition
93
-	 * @return Collection
94
-	 */
95
-	public function filter( $condition );
96
-
97
-	/**
98
-	 * Returns the last element in the collection that satisfies $condition,
99
-	 * returns false if no such element exists.
100
-	 *
101
-	 * @param callable $condition
102
-	 * @return mixed
103
-	 */
104
-	public function find_last( $condition );
105
-
106
-	/**
107
-	 * Returns the index of the last element in the collection that satisfies
108
-	 * $condition, returns -1 if no such element exists.
109
-	 *
110
-	 * @param callable $condition
111
-	 * @return int
112
-	 */
113
-	public function find_last_index( $condition );
114
-
115
-	/**
116
-	 * Returns a collection that contains the subset of elements ranging from the
117
-	 * index $start to $end.
118
-	 *
119
-	 * @param  int $start Begining index to slice from.
120
-	 * @param  int $end   End index to slice to.
121
-	 * @return Collection
122
-	 * @throws InvalidArgumentException
123
-	 */
124
-	public function slice( $start, $end );
125
-
126
-	/**
127
-	 * Inserts $element at $index.
128
-	 *
129
-	 * @param int   $index     Index to start at.
130
-	 * @param mixed $element Element to insert.
131
-	 * @return Collection
132
-	 * @throws InvalidArgumentException
133
-	 * @throws OutOfRangeException
134
-	 */
135
-	public function insert( $index, $element );
136
-
137
-	/**
138
-	 * Inserts the range $elements at $index.
139
-	 *
140
-	 * @param int   $index
141
-	 * @param array $elements
142
-	 * @return Collection
143
-	 * @throws OutOfRangeException
144
-	 */
145
-	public function insert_range( $index, array $elements );
146
-
147
-	/**
148
-	 * Removes all of the elements that satisfy $condition.
149
-	 *
150
-	 * @param  callable $condition
151
-	 * @return Collection
152
-	 */
153
-	public function without( $condition );
154
-
155
-	/**
156
-	 * Removes the element at $index.
157
-	 *
158
-	 * @param  int $index Index to remove.
159
-	 * @return Collection
160
-	 * @throws OutOfRangeException
161
-	 */
162
-	public function remove_at( $index );
163
-
164
-	/**
165
-	 * Reverses the order of the elements in the collection.
166
-	 *
167
-	 * @return Collection
168
-	 */
169
-	public function reverse();
170
-
171
-	/**
172
-	 * Sorts the elements in the collection using the user supplied comparison
173
-	 * function $callback.
174
-	 *
175
-	 * @param callable $callback
176
-	 * @return Collection
177
-	 */
178
-	public function sort( $callback );
179
-
180
-	/**
181
-	 * Returns an array containing the elements in the collection.
182
-	 *
183
-	 * @return array
184
-	 */
185
-	public function to_array();
186
-
187
-	/**
188
-	 * Iteratively reduces the collection to a single value using the callback
189
-	 * function $callable.
190
-	 *
191
-	 * @param callable $callable
192
-	 * @param null     $initial
193
-	 * @return mixed
194
-	 */
195
-	public function reduce( $callable, $initial = null );
196
-
197
-	/**
198
-	 * Returns true if every element in the collection satisfies $condition,
199
-	 * returns false if not.
200
-	 *
201
-	 * @param callable $condition
202
-	 * @return bool
203
-	 */
204
-	public function every( $condition );
205
-
206
-	/**
207
-	 * Removes all of the elements in the collection starting at index $num.
208
-	 *
209
-	 * @param  int $num Number of elements to drop.
210
-	 * @return Collection
211
-	 * @throws InvalidArgumentException
212
-	 */
213
-	public function drop( $num );
214
-
215
-	/**
216
-	 * Removes all of the elements in the collectioin between index 0 and $num.
217
-	 *
218
-	 * @param int $num Number of elements to drop.
219
-	 * @return Collection
220
-	 * @throws InvalidArgumentException
221
-	 */
222
-	public function drop_right( $num );
223
-
224
-	/**
225
-	 * Iteratively drops elements in the collection that satisfy $condition until
226
-	 * an element is encountered that does not satisfy $condition.
227
-	 *
228
-	 * @param callable $condition
229
-	 * @return Collection
230
-	 */
231
-	public function drop_while( $condition );
232
-
233
-	/**
234
-	 * Removes the first element in the collection.
235
-	 *
236
-	 * @return Collection
237
-	 * @throws InvalidArgumentException
238
-	 */
239
-	public function tail();
240
-
241
-	/**
242
-	 * Removes all of the elements in the collection starting at index $num.
243
-	 *
244
-	 * @param  int $num Number of elements to take.
245
-	 * @return Collection
246
-	 * @throws InvalidArgumentException
247
-	 */
248
-	public function take( $num );
249
-
250
-	/**
251
-	 * Removes all of the elements in the collection before index $num.
252
-	 *
253
-	 * @param int $num Number of elements to take.
254
-	 * @return Collection
255
-	 * @throws InvalidArgumentException
256
-	 */
257
-	public function take_right( $num );
258
-
259
-	/**
260
-	 * Iterates through the collection until an element is encountered that does
261
-	 * not satisfy $condition, then drops all of the elements starting at that
262
-	 * index.
263
-	 *
264
-	 * @param callable $condition
265
-	 * @return Collection
266
-	 */
267
-	public function take_while( $condition );
268
-
269
-	/**
270
-	 * Applies the callback function $callable to each element in the collection.
271
-	 *
272
-	 * @param callable $callable
273
-	 */
274
-	public function each( $callable );
275
-
276
-	/**
277
-	 * Returns a new instance of the collection with the callback function
278
-	 * $callable applied to each element.
279
-	 *
280
-	 * @param callable $callable
281
-	 * @return Collection
282
-	 */
283
-	public function map( $callable );
284
-
285
-	/**
286
-	 * Iteratively reduces the collection to a single value using the callback
287
-	 * function $callable starting at the rightmost index.
288
-	 *
289
-	 * @param callable $callable
290
-	 * @param null     $initial
291
-	 * @return mixed
292
-	 */
293
-	public function reduce_right( $callable, $initial = null );
294
-
295
-	/**
296
-	 * Randomly reorders the elements in the collection.
297
-	 *
298
-	 * @return Collection
299
-	 */
300
-	public function shuffle();
301
-
302
-	/**
303
-	 * Adds every member of $elements to the collection.
304
-	 *
305
-	 * @param array|Collection $elements Array of elements to merge.
306
-	 * @return Collection
307
-	 * @throws InvalidArgumentException
308
-	 */
309
-	public function merge( $elements );
310
-
311
-	/**
312
-	 * Get first element of the collection
313
-	 *
314
-	 * @return mixed
315
-	 * @throws OutOfBoundsException
316
-	 */
317
-	public function first();
318
-
319
-	/**
320
-	 * Get last element of the collection
321
-	 *
322
-	 * @return mixed
323
-	 * @throws OutOfBoundsException
324
-	 */
325
-	public function last();
12
+    /**
13
+     * Returns the type of the collection.
14
+     *
15
+     * @return string
16
+     */
17
+    public function get_type();
18
+
19
+    /**
20
+     * Returns a collection with $element added.
21
+     *
22
+     * @param  mixed $element
23
+     * @return Collection
24
+     * @throws InvalidArgumentException
25
+     */
26
+    public function add( $element );
27
+
28
+    /**
29
+     * Removes every element from the collection.
30
+     *
31
+     * @return Collection
32
+     */
33
+    public function clear();
34
+
35
+    /**
36
+     * Returns true if the collection contains any elements that satisfy
37
+     * $condition, returns false if it contains none.
38
+     *
39
+     * @param callable $condition
40
+     * @return bool
41
+     */
42
+    public function contains( $condition );
43
+
44
+    /**
45
+     * Returns the first element in the collection that satisfies
46
+     * $condition, returns false if no such element exists.
47
+     *
48
+     * @param callable $condition
49
+     * @return mixed
50
+     */
51
+    public function find( $condition );
52
+
53
+    /**
54
+     * Returns the index of the first element in the collection that satisfies
55
+     * $condition, returns -1 if no such element exists.
56
+     *
57
+     * @param callable $condition
58
+     * @return int
59
+     */
60
+    public function find_index( $condition );
61
+
62
+    /**
63
+     * Returns the element in the collection at $index.
64
+     *
65
+     * @param  int $index Index to get element from.
66
+     * @return mixed
67
+     * @throws OutOfRangeException
68
+     */
69
+    public function at( $index );
70
+
71
+    /**
72
+     * Returns true if $index is within the collection's range and returns false
73
+     * if it is not.
74
+     *
75
+     * @param  int $index Index to check for existence.
76
+     * @return bool
77
+     * @throws InvalidArgumentException
78
+     */
79
+    public function index_exists( $index );
80
+
81
+    /**
82
+     * Returns the number of elements in the collection.
83
+     *
84
+     * @return int
85
+     */
86
+    public function count();
87
+
88
+    /**
89
+     * Returns a collection that only contains the elements which satisfy
90
+     * $condition.
91
+     *
92
+     * @param callable $condition
93
+     * @return Collection
94
+     */
95
+    public function filter( $condition );
96
+
97
+    /**
98
+     * Returns the last element in the collection that satisfies $condition,
99
+     * returns false if no such element exists.
100
+     *
101
+     * @param callable $condition
102
+     * @return mixed
103
+     */
104
+    public function find_last( $condition );
105
+
106
+    /**
107
+     * Returns the index of the last element in the collection that satisfies
108
+     * $condition, returns -1 if no such element exists.
109
+     *
110
+     * @param callable $condition
111
+     * @return int
112
+     */
113
+    public function find_last_index( $condition );
114
+
115
+    /**
116
+     * Returns a collection that contains the subset of elements ranging from the
117
+     * index $start to $end.
118
+     *
119
+     * @param  int $start Begining index to slice from.
120
+     * @param  int $end   End index to slice to.
121
+     * @return Collection
122
+     * @throws InvalidArgumentException
123
+     */
124
+    public function slice( $start, $end );
125
+
126
+    /**
127
+     * Inserts $element at $index.
128
+     *
129
+     * @param int   $index     Index to start at.
130
+     * @param mixed $element Element to insert.
131
+     * @return Collection
132
+     * @throws InvalidArgumentException
133
+     * @throws OutOfRangeException
134
+     */
135
+    public function insert( $index, $element );
136
+
137
+    /**
138
+     * Inserts the range $elements at $index.
139
+     *
140
+     * @param int   $index
141
+     * @param array $elements
142
+     * @return Collection
143
+     * @throws OutOfRangeException
144
+     */
145
+    public function insert_range( $index, array $elements );
146
+
147
+    /**
148
+     * Removes all of the elements that satisfy $condition.
149
+     *
150
+     * @param  callable $condition
151
+     * @return Collection
152
+     */
153
+    public function without( $condition );
154
+
155
+    /**
156
+     * Removes the element at $index.
157
+     *
158
+     * @param  int $index Index to remove.
159
+     * @return Collection
160
+     * @throws OutOfRangeException
161
+     */
162
+    public function remove_at( $index );
163
+
164
+    /**
165
+     * Reverses the order of the elements in the collection.
166
+     *
167
+     * @return Collection
168
+     */
169
+    public function reverse();
170
+
171
+    /**
172
+     * Sorts the elements in the collection using the user supplied comparison
173
+     * function $callback.
174
+     *
175
+     * @param callable $callback
176
+     * @return Collection
177
+     */
178
+    public function sort( $callback );
179
+
180
+    /**
181
+     * Returns an array containing the elements in the collection.
182
+     *
183
+     * @return array
184
+     */
185
+    public function to_array();
186
+
187
+    /**
188
+     * Iteratively reduces the collection to a single value using the callback
189
+     * function $callable.
190
+     *
191
+     * @param callable $callable
192
+     * @param null     $initial
193
+     * @return mixed
194
+     */
195
+    public function reduce( $callable, $initial = null );
196
+
197
+    /**
198
+     * Returns true if every element in the collection satisfies $condition,
199
+     * returns false if not.
200
+     *
201
+     * @param callable $condition
202
+     * @return bool
203
+     */
204
+    public function every( $condition );
205
+
206
+    /**
207
+     * Removes all of the elements in the collection starting at index $num.
208
+     *
209
+     * @param  int $num Number of elements to drop.
210
+     * @return Collection
211
+     * @throws InvalidArgumentException
212
+     */
213
+    public function drop( $num );
214
+
215
+    /**
216
+     * Removes all of the elements in the collectioin between index 0 and $num.
217
+     *
218
+     * @param int $num Number of elements to drop.
219
+     * @return Collection
220
+     * @throws InvalidArgumentException
221
+     */
222
+    public function drop_right( $num );
223
+
224
+    /**
225
+     * Iteratively drops elements in the collection that satisfy $condition until
226
+     * an element is encountered that does not satisfy $condition.
227
+     *
228
+     * @param callable $condition
229
+     * @return Collection
230
+     */
231
+    public function drop_while( $condition );
232
+
233
+    /**
234
+     * Removes the first element in the collection.
235
+     *
236
+     * @return Collection
237
+     * @throws InvalidArgumentException
238
+     */
239
+    public function tail();
240
+
241
+    /**
242
+     * Removes all of the elements in the collection starting at index $num.
243
+     *
244
+     * @param  int $num Number of elements to take.
245
+     * @return Collection
246
+     * @throws InvalidArgumentException
247
+     */
248
+    public function take( $num );
249
+
250
+    /**
251
+     * Removes all of the elements in the collection before index $num.
252
+     *
253
+     * @param int $num Number of elements to take.
254
+     * @return Collection
255
+     * @throws InvalidArgumentException
256
+     */
257
+    public function take_right( $num );
258
+
259
+    /**
260
+     * Iterates through the collection until an element is encountered that does
261
+     * not satisfy $condition, then drops all of the elements starting at that
262
+     * index.
263
+     *
264
+     * @param callable $condition
265
+     * @return Collection
266
+     */
267
+    public function take_while( $condition );
268
+
269
+    /**
270
+     * Applies the callback function $callable to each element in the collection.
271
+     *
272
+     * @param callable $callable
273
+     */
274
+    public function each( $callable );
275
+
276
+    /**
277
+     * Returns a new instance of the collection with the callback function
278
+     * $callable applied to each element.
279
+     *
280
+     * @param callable $callable
281
+     * @return Collection
282
+     */
283
+    public function map( $callable );
284
+
285
+    /**
286
+     * Iteratively reduces the collection to a single value using the callback
287
+     * function $callable starting at the rightmost index.
288
+     *
289
+     * @param callable $callable
290
+     * @param null     $initial
291
+     * @return mixed
292
+     */
293
+    public function reduce_right( $callable, $initial = null );
294
+
295
+    /**
296
+     * Randomly reorders the elements in the collection.
297
+     *
298
+     * @return Collection
299
+     */
300
+    public function shuffle();
301
+
302
+    /**
303
+     * Adds every member of $elements to the collection.
304
+     *
305
+     * @param array|Collection $elements Array of elements to merge.
306
+     * @return Collection
307
+     * @throws InvalidArgumentException
308
+     */
309
+    public function merge( $elements );
310
+
311
+    /**
312
+     * Get first element of the collection
313
+     *
314
+     * @return mixed
315
+     * @throws OutOfBoundsException
316
+     */
317
+    public function first();
318
+
319
+    /**
320
+     * Get last element of the collection
321
+     *
322
+     * @return mixed
323
+     * @throws OutOfBoundsException
324
+     */
325
+    public function last();
326 326
 }
Please login to merge, or discard this patch.
Spacing   +27 added lines, -27 removed lines patch added patch discarded remove patch
@@ -23,7 +23,7 @@  discard block
 block discarded – undo
23 23
 	 * @return Collection
24 24
 	 * @throws InvalidArgumentException
25 25
 	 */
26
-	public function add( $element );
26
+	public function add($element);
27 27
 
28 28
 	/**
29 29
 	 * Removes every element from the collection.
@@ -39,7 +39,7 @@  discard block
 block discarded – undo
39 39
 	 * @param callable $condition
40 40
 	 * @return bool
41 41
 	 */
42
-	public function contains( $condition );
42
+	public function contains($condition);
43 43
 
44 44
 	/**
45 45
 	 * Returns the first element in the collection that satisfies
@@ -48,7 +48,7 @@  discard block
 block discarded – undo
48 48
 	 * @param callable $condition
49 49
 	 * @return mixed
50 50
 	 */
51
-	public function find( $condition );
51
+	public function find($condition);
52 52
 
53 53
 	/**
54 54
 	 * Returns the index of the first element in the collection that satisfies
@@ -57,7 +57,7 @@  discard block
 block discarded – undo
57 57
 	 * @param callable $condition
58 58
 	 * @return int
59 59
 	 */
60
-	public function find_index( $condition );
60
+	public function find_index($condition);
61 61
 
62 62
 	/**
63 63
 	 * Returns the element in the collection at $index.
@@ -66,7 +66,7 @@  discard block
 block discarded – undo
66 66
 	 * @return mixed
67 67
 	 * @throws OutOfRangeException
68 68
 	 */
69
-	public function at( $index );
69
+	public function at($index);
70 70
 
71 71
 	/**
72 72
 	 * Returns true if $index is within the collection's range and returns false
@@ -76,7 +76,7 @@  discard block
 block discarded – undo
76 76
 	 * @return bool
77 77
 	 * @throws InvalidArgumentException
78 78
 	 */
79
-	public function index_exists( $index );
79
+	public function index_exists($index);
80 80
 
81 81
 	/**
82 82
 	 * Returns the number of elements in the collection.
@@ -92,7 +92,7 @@  discard block
 block discarded – undo
92 92
 	 * @param callable $condition
93 93
 	 * @return Collection
94 94
 	 */
95
-	public function filter( $condition );
95
+	public function filter($condition);
96 96
 
97 97
 	/**
98 98
 	 * Returns the last element in the collection that satisfies $condition,
@@ -101,7 +101,7 @@  discard block
 block discarded – undo
101 101
 	 * @param callable $condition
102 102
 	 * @return mixed
103 103
 	 */
104
-	public function find_last( $condition );
104
+	public function find_last($condition);
105 105
 
106 106
 	/**
107 107
 	 * Returns the index of the last element in the collection that satisfies
@@ -110,7 +110,7 @@  discard block
 block discarded – undo
110 110
 	 * @param callable $condition
111 111
 	 * @return int
112 112
 	 */
113
-	public function find_last_index( $condition );
113
+	public function find_last_index($condition);
114 114
 
115 115
 	/**
116 116
 	 * Returns a collection that contains the subset of elements ranging from the
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
 	 * @return Collection
122 122
 	 * @throws InvalidArgumentException
123 123
 	 */
124
-	public function slice( $start, $end );
124
+	public function slice($start, $end);
125 125
 
126 126
 	/**
127 127
 	 * Inserts $element at $index.
@@ -132,7 +132,7 @@  discard block
 block discarded – undo
132 132
 	 * @throws InvalidArgumentException
133 133
 	 * @throws OutOfRangeException
134 134
 	 */
135
-	public function insert( $index, $element );
135
+	public function insert($index, $element);
136 136
 
137 137
 	/**
138 138
 	 * Inserts the range $elements at $index.
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
 	 * @return Collection
143 143
 	 * @throws OutOfRangeException
144 144
 	 */
145
-	public function insert_range( $index, array $elements );
145
+	public function insert_range($index, array $elements);
146 146
 
147 147
 	/**
148 148
 	 * Removes all of the elements that satisfy $condition.
@@ -150,7 +150,7 @@  discard block
 block discarded – undo
150 150
 	 * @param  callable $condition
151 151
 	 * @return Collection
152 152
 	 */
153
-	public function without( $condition );
153
+	public function without($condition);
154 154
 
155 155
 	/**
156 156
 	 * Removes the element at $index.
@@ -159,7 +159,7 @@  discard block
 block discarded – undo
159 159
 	 * @return Collection
160 160
 	 * @throws OutOfRangeException
161 161
 	 */
162
-	public function remove_at( $index );
162
+	public function remove_at($index);
163 163
 
164 164
 	/**
165 165
 	 * Reverses the order of the elements in the collection.
@@ -175,7 +175,7 @@  discard block
 block discarded – undo
175 175
 	 * @param callable $callback
176 176
 	 * @return Collection
177 177
 	 */
178
-	public function sort( $callback );
178
+	public function sort($callback);
179 179
 
180 180
 	/**
181 181
 	 * Returns an array containing the elements in the collection.
@@ -192,7 +192,7 @@  discard block
 block discarded – undo
192 192
 	 * @param null     $initial
193 193
 	 * @return mixed
194 194
 	 */
195
-	public function reduce( $callable, $initial = null );
195
+	public function reduce($callable, $initial = null);
196 196
 
197 197
 	/**
198 198
 	 * Returns true if every element in the collection satisfies $condition,
@@ -201,7 +201,7 @@  discard block
 block discarded – undo
201 201
 	 * @param callable $condition
202 202
 	 * @return bool
203 203
 	 */
204
-	public function every( $condition );
204
+	public function every($condition);
205 205
 
206 206
 	/**
207 207
 	 * Removes all of the elements in the collection starting at index $num.
@@ -210,7 +210,7 @@  discard block
 block discarded – undo
210 210
 	 * @return Collection
211 211
 	 * @throws InvalidArgumentException
212 212
 	 */
213
-	public function drop( $num );
213
+	public function drop($num);
214 214
 
215 215
 	/**
216 216
 	 * Removes all of the elements in the collectioin between index 0 and $num.
@@ -219,7 +219,7 @@  discard block
 block discarded – undo
219 219
 	 * @return Collection
220 220
 	 * @throws InvalidArgumentException
221 221
 	 */
222
-	public function drop_right( $num );
222
+	public function drop_right($num);
223 223
 
224 224
 	/**
225 225
 	 * Iteratively drops elements in the collection that satisfy $condition until
@@ -228,7 +228,7 @@  discard block
 block discarded – undo
228 228
 	 * @param callable $condition
229 229
 	 * @return Collection
230 230
 	 */
231
-	public function drop_while( $condition );
231
+	public function drop_while($condition);
232 232
 
233 233
 	/**
234 234
 	 * Removes the first element in the collection.
@@ -245,7 +245,7 @@  discard block
 block discarded – undo
245 245
 	 * @return Collection
246 246
 	 * @throws InvalidArgumentException
247 247
 	 */
248
-	public function take( $num );
248
+	public function take($num);
249 249
 
250 250
 	/**
251 251
 	 * Removes all of the elements in the collection before index $num.
@@ -254,7 +254,7 @@  discard block
 block discarded – undo
254 254
 	 * @return Collection
255 255
 	 * @throws InvalidArgumentException
256 256
 	 */
257
-	public function take_right( $num );
257
+	public function take_right($num);
258 258
 
259 259
 	/**
260 260
 	 * Iterates through the collection until an element is encountered that does
@@ -264,14 +264,14 @@  discard block
 block discarded – undo
264 264
 	 * @param callable $condition
265 265
 	 * @return Collection
266 266
 	 */
267
-	public function take_while( $condition );
267
+	public function take_while($condition);
268 268
 
269 269
 	/**
270 270
 	 * Applies the callback function $callable to each element in the collection.
271 271
 	 *
272 272
 	 * @param callable $callable
273 273
 	 */
274
-	public function each( $callable );
274
+	public function each($callable);
275 275
 
276 276
 	/**
277 277
 	 * Returns a new instance of the collection with the callback function
@@ -280,7 +280,7 @@  discard block
 block discarded – undo
280 280
 	 * @param callable $callable
281 281
 	 * @return Collection
282 282
 	 */
283
-	public function map( $callable );
283
+	public function map($callable);
284 284
 
285 285
 	/**
286 286
 	 * Iteratively reduces the collection to a single value using the callback
@@ -290,7 +290,7 @@  discard block
 block discarded – undo
290 290
 	 * @param null     $initial
291 291
 	 * @return mixed
292 292
 	 */
293
-	public function reduce_right( $callable, $initial = null );
293
+	public function reduce_right($callable, $initial = null);
294 294
 
295 295
 	/**
296 296
 	 * Randomly reorders the elements in the collection.
@@ -306,7 +306,7 @@  discard block
 block discarded – undo
306 306
 	 * @return Collection
307 307
 	 * @throws InvalidArgumentException
308 308
 	 */
309
-	public function merge( $elements );
309
+	public function merge($elements);
310 310
 
311 311
 	/**
312 312
 	 * Get first element of the collection
Please login to merge, or discard this patch.
src/Axolotl/Type.php 2 patches
Indentation   +153 added lines, -153 removed lines patch added patch discarded remove patch
@@ -15,157 +15,157 @@
 block discarded – undo
15 15
  */
16 16
 class Type {
17 17
 
18
-	/**
19
-	 * Type to validate against.
20
-	 *
21
-	 * @var string
22
-	 */
23
-	private $type;
24
-
25
-	/**
26
-	 * Type constructor.
27
-	 *
28
-	 * @param string $type
29
-	 */
30
-	public function __construct( $type ) {
31
-		$this->type = $this->determine( $type );
32
-	}
33
-
34
-	/**
35
-	 * Get validation type.
36
-	 *
37
-	 * @return string
38
-	 */
39
-	public function get_type() {
40
-		return $this->type;
41
-	}
42
-
43
-	/**
44
-	 * Returns whether the type is an Axolotl model.
45
-	 *
46
-	 * @return bool
47
-	 */
48
-	public function is_model() {
49
-		if ( ! class_exists( $this->type ) ) {
50
-			return false;
51
-		}
52
-
53
-		$reflection = new ReflectionClass( $this->type );
54
-		return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' );
55
-	}
56
-
57
-	/**
58
-	 * Create a new model from the given data.
59
-	 *
60
-	 * @param array $data Data for the model.
61
-	 *
62
-	 * @return Model
63
-	 */
64
-	public function create_model( array $data ) {
65
-		return new $this->type( $data );
66
-	}
67
-
68
-	/**
69
-	 * Validates an array of element.
70
-	 *
71
-	 * @param array $elements Elements to be validated.
72
-	 *
73
-	 * @throws InvalidArgumentException
74
-	 */
75
-	public function validate_elements( array $elements ) {
76
-		foreach ( $elements as $element ) {
77
-			$this->validate_element( $element );
78
-		}
79
-	}
80
-
81
-	/**
82
-	 * Validate whether the
83
-	 *
84
-	 * @param mixed $element Element to validate.
85
-	 *
86
-	 * @throws InvalidArgumentException
87
-	 */
88
-	public function validate_element( $element ) {
89
-		$type = gettype( $element );
90
-		$callable = $this->type === 'callable';
91
-		$is_object = 'object' === $type;
92
-		$loose_check = $this->type === 'object';
93
-
94
-		// callable must be callable
95
-		if ( $callable && ! is_callable( $element ) ) {
96
-			throw new InvalidArgumentException( 'Item must be callable' );
97
-		}
98
-
99
-		// target isn't callable, object must be an instance of target
100
-		if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) {
101
-			throw new InvalidArgumentException( "Item is not type or subtype of $this->type" );
102
-		}
103
-
104
-		// a non callable, non object type should match the target string
105
-		if ( ! $callable && ! $is_object && $type !== $this->type ) {
106
-			throw new InvalidArgumentException( "Item is not of type: $this->type" );
107
-		}
108
-	}
109
-
110
-	/**
111
-	 * Determine the type to validate against.
112
-	 *
113
-	 * @param string $type     Type to determine.
114
-	 * @param bool   $key_type Whether the type is for keys.
115
-	 *
116
-	 * @return string
117
-	 *
118
-	 * @throws InvalidArgumentException
119
-	 */
120
-	private function determine( $type, $key_type = false ) {
121
-		if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) {
122
-			return $type;
123
-		}
124
-
125
-		if ( $scalar_type = $this->determine_scalar( $type ) ) {
126
-			if ( $key_type && (in_array( $scalar_type, array( 'double', 'boolean' ) )) ) {
127
-				throw new InvalidArgumentException( 'This type is not supported as a key.' );
128
-			}
129
-
130
-			return $scalar_type;
131
-		}
132
-
133
-		throw new InvalidArgumentException( 'This type does not exist.' );
134
-	}
135
-
136
-	/**
137
-	 * Determines whether the given type exists.
138
-	 *
139
-	 * @param string $type Type to check.
140
-	 *
141
-	 * @return bool
142
-	 */
143
-	private function non_scalar_type_exists( $type ) {
144
-		return class_exists( $type )
145
-				|| interface_exists( $type )
146
-				|| in_array( $type, array( 'array', 'object', 'callable' ) );
147
-	}
148
-
149
-	/**
150
-	 * Returns the type if it's scalar, otherwise, returns null.
151
-	 *
152
-	 * @param string $type Type to check.
153
-	 *
154
-	 * @return string|null
155
-	 */
156
-	private function determine_scalar( $type ) {
157
-		$synonyms = array(
158
-			'int' => 'integer',
159
-			'float' => 'double',
160
-			'bool' => 'boolean',
161
-		);
162
-
163
-		if ( array_key_exists( $type, $synonyms ) ) {
164
-			$type = $synonyms[ $type ];
165
-		}
166
-
167
-		return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ?
168
-			$type :
169
-			null;
170
-	}
18
+    /**
19
+     * Type to validate against.
20
+     *
21
+     * @var string
22
+     */
23
+    private $type;
24
+
25
+    /**
26
+     * Type constructor.
27
+     *
28
+     * @param string $type
29
+     */
30
+    public function __construct( $type ) {
31
+        $this->type = $this->determine( $type );
32
+    }
33
+
34
+    /**
35
+     * Get validation type.
36
+     *
37
+     * @return string
38
+     */
39
+    public function get_type() {
40
+        return $this->type;
41
+    }
42
+
43
+    /**
44
+     * Returns whether the type is an Axolotl model.
45
+     *
46
+     * @return bool
47
+     */
48
+    public function is_model() {
49
+        if ( ! class_exists( $this->type ) ) {
50
+            return false;
51
+        }
52
+
53
+        $reflection = new ReflectionClass( $this->type );
54
+        return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' );
55
+    }
56
+
57
+    /**
58
+     * Create a new model from the given data.
59
+     *
60
+     * @param array $data Data for the model.
61
+     *
62
+     * @return Model
63
+     */
64
+    public function create_model( array $data ) {
65
+        return new $this->type( $data );
66
+    }
67
+
68
+    /**
69
+     * Validates an array of element.
70
+     *
71
+     * @param array $elements Elements to be validated.
72
+     *
73
+     * @throws InvalidArgumentException
74
+     */
75
+    public function validate_elements( array $elements ) {
76
+        foreach ( $elements as $element ) {
77
+            $this->validate_element( $element );
78
+        }
79
+    }
80
+
81
+    /**
82
+     * Validate whether the
83
+     *
84
+     * @param mixed $element Element to validate.
85
+     *
86
+     * @throws InvalidArgumentException
87
+     */
88
+    public function validate_element( $element ) {
89
+        $type = gettype( $element );
90
+        $callable = $this->type === 'callable';
91
+        $is_object = 'object' === $type;
92
+        $loose_check = $this->type === 'object';
93
+
94
+        // callable must be callable
95
+        if ( $callable && ! is_callable( $element ) ) {
96
+            throw new InvalidArgumentException( 'Item must be callable' );
97
+        }
98
+
99
+        // target isn't callable, object must be an instance of target
100
+        if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) {
101
+            throw new InvalidArgumentException( "Item is not type or subtype of $this->type" );
102
+        }
103
+
104
+        // a non callable, non object type should match the target string
105
+        if ( ! $callable && ! $is_object && $type !== $this->type ) {
106
+            throw new InvalidArgumentException( "Item is not of type: $this->type" );
107
+        }
108
+    }
109
+
110
+    /**
111
+     * Determine the type to validate against.
112
+     *
113
+     * @param string $type     Type to determine.
114
+     * @param bool   $key_type Whether the type is for keys.
115
+     *
116
+     * @return string
117
+     *
118
+     * @throws InvalidArgumentException
119
+     */
120
+    private function determine( $type, $key_type = false ) {
121
+        if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) {
122
+            return $type;
123
+        }
124
+
125
+        if ( $scalar_type = $this->determine_scalar( $type ) ) {
126
+            if ( $key_type && (in_array( $scalar_type, array( 'double', 'boolean' ) )) ) {
127
+                throw new InvalidArgumentException( 'This type is not supported as a key.' );
128
+            }
129
+
130
+            return $scalar_type;
131
+        }
132
+
133
+        throw new InvalidArgumentException( 'This type does not exist.' );
134
+    }
135
+
136
+    /**
137
+     * Determines whether the given type exists.
138
+     *
139
+     * @param string $type Type to check.
140
+     *
141
+     * @return bool
142
+     */
143
+    private function non_scalar_type_exists( $type ) {
144
+        return class_exists( $type )
145
+                || interface_exists( $type )
146
+                || in_array( $type, array( 'array', 'object', 'callable' ) );
147
+    }
148
+
149
+    /**
150
+     * Returns the type if it's scalar, otherwise, returns null.
151
+     *
152
+     * @param string $type Type to check.
153
+     *
154
+     * @return string|null
155
+     */
156
+    private function determine_scalar( $type ) {
157
+        $synonyms = array(
158
+            'int' => 'integer',
159
+            'float' => 'double',
160
+            'bool' => 'boolean',
161
+        );
162
+
163
+        if ( array_key_exists( $type, $synonyms ) ) {
164
+            $type = $synonyms[ $type ];
165
+        }
166
+
167
+        return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ?
168
+            $type :
169
+            null;
170
+    }
171 171
 }
Please login to merge, or discard this patch.
Spacing   +33 added lines, -34 removed lines patch added patch discarded remove patch
@@ -27,8 +27,8 @@  discard block
 block discarded – undo
27 27
 	 *
28 28
 	 * @param string $type
29 29
 	 */
30
-	public function __construct( $type ) {
31
-		$this->type = $this->determine( $type );
30
+	public function __construct($type) {
31
+		$this->type = $this->determine($type);
32 32
 	}
33 33
 
34 34
 	/**
@@ -46,12 +46,12 @@  discard block
 block discarded – undo
46 46
 	 * @return bool
47 47
 	 */
48 48
 	public function is_model() {
49
-		if ( ! class_exists( $this->type ) ) {
49
+		if (!class_exists($this->type)) {
50 50
 			return false;
51 51
 		}
52 52
 
53
-		$reflection = new ReflectionClass( $this->type );
54
-		return $reflection->isSubclassOf( 'Intraxia\Jaxion\Axolotl\Model' );
53
+		$reflection = new ReflectionClass($this->type);
54
+		return $reflection->isSubclassOf('Intraxia\Jaxion\Axolotl\Model');
55 55
 	}
56 56
 
57 57
 	/**
@@ -61,8 +61,8 @@  discard block
 block discarded – undo
61 61
 	 *
62 62
 	 * @return Model
63 63
 	 */
64
-	public function create_model( array $data ) {
65
-		return new $this->type( $data );
64
+	public function create_model(array $data) {
65
+		return new $this->type($data);
66 66
 	}
67 67
 
68 68
 	/**
@@ -72,9 +72,9 @@  discard block
 block discarded – undo
72 72
 	 *
73 73
 	 * @throws InvalidArgumentException
74 74
 	 */
75
-	public function validate_elements( array $elements ) {
76
-		foreach ( $elements as $element ) {
77
-			$this->validate_element( $element );
75
+	public function validate_elements(array $elements) {
76
+		foreach ($elements as $element) {
77
+			$this->validate_element($element);
78 78
 		}
79 79
 	}
80 80
 
@@ -85,25 +85,25 @@  discard block
 block discarded – undo
85 85
 	 *
86 86
 	 * @throws InvalidArgumentException
87 87
 	 */
88
-	public function validate_element( $element ) {
89
-		$type = gettype( $element );
88
+	public function validate_element($element) {
89
+		$type = gettype($element);
90 90
 		$callable = $this->type === 'callable';
91 91
 		$is_object = 'object' === $type;
92 92
 		$loose_check = $this->type === 'object';
93 93
 
94 94
 		// callable must be callable
95
-		if ( $callable && ! is_callable( $element ) ) {
96
-			throw new InvalidArgumentException( 'Item must be callable' );
95
+		if ($callable && !is_callable($element)) {
96
+			throw new InvalidArgumentException('Item must be callable');
97 97
 		}
98 98
 
99 99
 		// target isn't callable, object must be an instance of target
100
-		if ( ! $loose_check && ! $callable && $is_object && ! is_a( $element, $this->type ) ) {
101
-			throw new InvalidArgumentException( "Item is not type or subtype of $this->type" );
100
+		if (!$loose_check && !$callable && $is_object && !is_a($element, $this->type)) {
101
+			throw new InvalidArgumentException("Item is not type or subtype of $this->type");
102 102
 		}
103 103
 
104 104
 		// a non callable, non object type should match the target string
105
-		if ( ! $callable && ! $is_object && $type !== $this->type ) {
106
-			throw new InvalidArgumentException( "Item is not of type: $this->type" );
105
+		if (!$callable && !$is_object && $type !== $this->type) {
106
+			throw new InvalidArgumentException("Item is not of type: $this->type");
107 107
 		}
108 108
 	}
109 109
 
@@ -117,20 +117,20 @@  discard block
 block discarded – undo
117 117
 	 *
118 118
 	 * @throws InvalidArgumentException
119 119
 	 */
120
-	private function determine( $type, $key_type = false ) {
121
-		if ( ! $key_type && $this->non_scalar_type_exists( $type ) ) {
120
+	private function determine($type, $key_type = false) {
121
+		if (!$key_type && $this->non_scalar_type_exists($type)) {
122 122
 			return $type;
123 123
 		}
124 124
 
125
-		if ( $scalar_type = $this->determine_scalar( $type ) ) {
126
-			if ( $key_type && (in_array( $scalar_type, array( 'double', 'boolean' ) )) ) {
127
-				throw new InvalidArgumentException( 'This type is not supported as a key.' );
125
+		if ($scalar_type = $this->determine_scalar($type)) {
126
+			if ($key_type && (in_array($scalar_type, array('double', 'boolean')))) {
127
+				throw new InvalidArgumentException('This type is not supported as a key.');
128 128
 			}
129 129
 
130 130
 			return $scalar_type;
131 131
 		}
132 132
 
133
-		throw new InvalidArgumentException( 'This type does not exist.' );
133
+		throw new InvalidArgumentException('This type does not exist.');
134 134
 	}
135 135
 
136 136
 	/**
@@ -140,10 +140,10 @@  discard block
 block discarded – undo
140 140
 	 *
141 141
 	 * @return bool
142 142
 	 */
143
-	private function non_scalar_type_exists( $type ) {
144
-		return class_exists( $type )
145
-				|| interface_exists( $type )
146
-				|| in_array( $type, array( 'array', 'object', 'callable' ) );
143
+	private function non_scalar_type_exists($type) {
144
+		return class_exists($type)
145
+				|| interface_exists($type)
146
+				|| in_array($type, array('array', 'object', 'callable'));
147 147
 	}
148 148
 
149 149
 	/**
@@ -153,19 +153,18 @@  discard block
 block discarded – undo
153 153
 	 *
154 154
 	 * @return string|null
155 155
 	 */
156
-	private function determine_scalar( $type ) {
156
+	private function determine_scalar($type) {
157 157
 		$synonyms = array(
158 158
 			'int' => 'integer',
159 159
 			'float' => 'double',
160 160
 			'bool' => 'boolean',
161 161
 		);
162 162
 
163
-		if ( array_key_exists( $type, $synonyms ) ) {
164
-			$type = $synonyms[ $type ];
163
+		if (array_key_exists($type, $synonyms)) {
164
+			$type = $synonyms[$type];
165 165
 		}
166 166
 
167
-		return in_array( $type, array( 'string', 'integer', 'double', 'boolean' ) ) ?
168
-			$type :
169
-			null;
167
+		return in_array($type, array('string', 'integer', 'double', 'boolean')) ?
168
+			$type : null;
170 169
 	}
171 170
 }
Please login to merge, or discard this patch.