Completed
Pull Request — master (#30)
by Alexey
01:35
created
YaLinqo/EnumerableGeneration.php 2 patches
Doc Comments   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@  discard block
 block discarded – undo
13 13
      * @param array|\Iterator|\IteratorAggregate|Enumerable $source Source sequence.
14 14
      * @throws \InvalidArgumentException If source is not array or Traversible or Enumerable.
15 15
      * @throws \UnexpectedValueException If source contains no elements (checked during enumeration).
16
-     * @return Enumerable Endless list of items repeating the source sequence.
16
+     * @return EnumerableGeneration Endless list of items repeating the source sequence.
17 17
      * @package YaLinqo\Generation
18 18
      */
19 19
     public static function cycle ($source)
@@ -36,7 +36,7 @@  discard block
 block discarded – undo
36 36
     /**
37 37
      * Returns an empty sequence.
38 38
      * <p><b>Syntax</b>: emptyEnum ()
39
-     * @return Enumerable
39
+     * @return EnumerableGeneration
40 40
      * @package YaLinqo\Generation
41 41
      */
42 42
     public static function emptyEnum ()
@@ -84,7 +84,7 @@  discard block
 block discarded – undo
84 84
      * @param mixed $seedValue Initial state of the generator loop for values. Default: null.
85 85
      * @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment.
86 86
      * @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0.
87
-     * @return Enumerable
87
+     * @return EnumerableGeneration
88 88
      * @package YaLinqo\Generation
89 89
      */
90 90
     public static function generate ($funcValue, $seedValue = null, $funcKey = null, $seedKey = null)
@@ -111,7 +111,7 @@  discard block
 block discarded – undo
111 111
      * <p><b>Syntax</b>: toInfinity ([start [, step]])
112 112
      * @param int $start The first integer in the sequence. Default: 0.
113 113
      * @param int $step The difference between adjacent integers. Default: 1.
114
-     * @return Enumerable
114
+     * @return EnumerableGeneration
115 115
      * @package YaLinqo\Generation
116 116
      */
117 117
     public static function toInfinity ($start = 0, $step = 1)
@@ -129,7 +129,7 @@  discard block
 block discarded – undo
129 129
      * @param string $subject The input string.
130 130
      * @param string $pattern The pattern to search for, as a string.
131 131
      * @param int $flags Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER.
132
-     * @return Enumerable
132
+     * @return EnumerableGeneration
133 133
      * @see preg_match_all
134 134
      * @package YaLinqo\Generation
135 135
      */
@@ -146,7 +146,7 @@  discard block
 block discarded – undo
146 146
      * <p><b>Syntax</b>: toNegativeInfinity ([start [, step]])
147 147
      * @param int $start The first integer in the sequence. Default: 0.
148 148
      * @param int $step The difference between adjacent integers. Default: 1.
149
-     * @return Enumerable
149
+     * @return EnumerableGeneration
150 150
      * @package YaLinqo\Generation
151 151
      */
152 152
     public static function toNegativeInfinity ($start = 0, $step = 1)
@@ -158,7 +158,7 @@  discard block
 block discarded – undo
158 158
      * Returns a sequence that contains a single element with a specified value.
159 159
      * <p><b>Syntax</b>: returnEnum (element)
160 160
      * @param mixed $element The single element in the resulting sequence.
161
-     * @return Enumerable Observable sequence containing the single specified element.
161
+     * @return EnumerableGeneration Observable sequence containing the single specified element.
162 162
      * @package YaLinqo\Generation
163 163
      */
164 164
     public static function returnEnum ($element)
@@ -174,7 +174,7 @@  discard block
 block discarded – undo
174 174
      * @param int $start The value of the first integer in the sequence.
175 175
      * @param int $count The number of integers to generate.
176 176
      * @param int $step The difference between adjacent integers. Default: 1.
177
-     * @return Enumerable A sequence that contains a range of integral numbers.
177
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
178 178
      * @package YaLinqo\Generation
179 179
      */
180 180
     public static function range ($start, $count, $step = 1)
@@ -196,7 +196,7 @@  discard block
 block discarded – undo
196 196
      * @param int $start The value of the first integer in the sequence.
197 197
      * @param int $count The number of integers to generate.
198 198
      * @param int $step The difference between adjacent integers. Default: 1.
199
-     * @return Enumerable A sequence that contains a range of integral numbers.
199
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
200 200
      * @package YaLinqo\Generation
201 201
      */
202 202
     public static function rangeDown ($start, $count, $step = 1)
@@ -213,7 +213,7 @@  discard block
 block discarded – undo
213 213
      * @param int $end The value of the last integer in the sequence (not included).
214 214
      * @param int $step The difference between adjacent integers. Default: 1.
215 215
      * @throws \InvalidArgumentException If step is not a positive number.
216
-     * @return Enumerable A sequence that contains a range of integral numbers.
216
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
217 217
      * @package YaLinqo\Generation
218 218
      */
219 219
     public static function rangeTo ($start, $end, $step = 1)
@@ -242,7 +242,7 @@  discard block
 block discarded – undo
242 242
      * @param int $element The value to be repeated.
243 243
      * @param int $count The number of times to repeat the value in the generated sequence. Default: null.
244 244
      * @throws \InvalidArgumentException If count is less than 0.
245
-     * @return Enumerable A sequence that contains a repeated value.
245
+     * @return EnumerableGeneration A sequence that contains a repeated value.
246 246
      * @package YaLinqo\Generation
247 247
      */
248 248
     public static function repeat ($element, $count = null)
@@ -261,7 +261,7 @@  discard block
 block discarded – undo
261 261
      * @param string $subject The input string.
262 262
      * @param string $pattern The pattern to search for, as a string.
263 263
      * @param int $flags flags can be any combination of the following flags: PREG_SPLIT_NO_EMPTY, PREG_SPLIT_DELIM_CAPTURE, PREG_SPLIT_OFFSET_CAPTURE. Default: 0.
264
-     * @return Enumerable
264
+     * @return EnumerableGeneration
265 265
      * @see preg_split
266 266
      * @package YaLinqo\Generation
267 267
      */
Please login to merge, or discard this patch.
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -27,8 +27,9 @@  discard block
 block discarded – undo
27 27
                     yield $v;
28 28
                     $isEmpty = false;
29 29
                 }
30
-                if ($isEmpty)
31
-                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
30
+                if ($isEmpty) {
31
+                                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
32
+                }
32 33
             }
33 34
         });
34 35
     }
@@ -63,14 +64,15 @@  discard block
 block discarded – undo
63 64
     public static function from ($source)
64 65
     {
65 66
         $it = null;
66
-        if ($source instanceof Enumerable)
67
-            return $source;
68
-        else if (is_array($source))
69
-            $it = new \ArrayIterator($source);
70
-        elseif ($source instanceof \IteratorAggregate)
71
-            $it = $source->getIterator();
72
-        elseif ($source instanceof \Traversable)
73
-            $it = $source;
67
+        if ($source instanceof Enumerable) {
68
+                    return $source;
69
+        } else if (is_array($source)) {
70
+                    $it = new \ArrayIterator($source);
71
+        } elseif ($source instanceof \IteratorAggregate) {
72
+                    $it = $source->getIterator();
73
+        } elseif ($source instanceof \Traversable) {
74
+                    $it = $source;
75
+        }
74 76
         if ($it !== null) {
75 77
             return new self($it, false);
76 78
         }
@@ -119,8 +121,9 @@  discard block
 block discarded – undo
119 121
     {
120 122
         return new self(function () use ($start, $step) {
121 123
             $value = $start - $step;
122
-            while (true)
123
-                yield $value += $step;
124
+            while (true) {
125
+                            yield $value += $step;
126
+            }
124 127
         });
125 128
     }
126 129
 
@@ -180,12 +183,14 @@  discard block
 block discarded – undo
180 183
      */
181 184
     public static function range ($start, $count, $step = 1)
182 185
     {
183
-        if ($count <= 0)
184
-            return self::emptyEnum();
186
+        if ($count <= 0) {
187
+                    return self::emptyEnum();
188
+        }
185 189
         return new self(function () use ($start, $count, $step) {
186 190
             $value = $start - $step;
187
-            while ($count-- > 0)
188
-                yield $value += $step;
191
+            while ($count-- > 0) {
192
+                            yield $value += $step;
193
+            }
189 194
         });
190 195
     }
191 196
 
@@ -219,16 +224,18 @@  discard block
 block discarded – undo
219 224
      */
220 225
     public static function rangeTo ($start, $end, $step = 1)
221 226
     {
222
-        if ($step <= 0)
223
-            throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
227
+        if ($step <= 0) {
228
+                    throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
229
+        }
224 230
         return new self(function () use ($start, $end, $step) {
225 231
             if ($start <= $end) {
226
-                for ($i = $start; $i < $end; $i += $step)
227
-                    yield $i;
228
-            }
229
-            else {
230
-                for ($i = $start; $i > $end; $i -= $step)
231
-                    yield $i;
232
+                for ($i = $start; $i < $end; $i += $step) {
233
+                                    yield $i;
234
+                }
235
+            } else {
236
+                for ($i = $start; $i > $end; $i -= $step) {
237
+                                    yield $i;
238
+                }
232 239
             }
233 240
         });
234 241
     }
@@ -248,11 +255,13 @@  discard block
 block discarded – undo
248 255
      */
249 256
     public static function repeat ($element, $count = null)
250 257
     {
251
-        if ($count < 0)
252
-            throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
258
+        if ($count < 0) {
259
+                    throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
260
+        }
253 261
         return new self(function () use ($element, $count) {
254
-            for ($i = 0; $i < $count || $count === null; $i++)
255
-                yield $element;
262
+            for ($i = 0; $i < $count || $count === null; $i++) {
263
+                            yield $element;
264
+            }
256 265
         });
257 266
     }
258 267
 
Please login to merge, or discard this patch.
YaLinqo/EnumerablePagination.php 2 patches
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -385,7 +385,7 @@  discard block
 block discarded – undo
385 385
      * <p>If source contains fewer than count elements, an empty sequence is returned. If count is less than or equal to zero, all elements of source are yielded.
386 386
      * <p>The {@link take} and skip methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll.
387 387
      * @param int $count The number of elements to skip before returning the remaining elements.
388
-     * @return Enumerable A sequence that contains the elements that occur after the specified index in the input sequence.
388
+     * @return EnumerablePagination A sequence that contains the elements that occur after the specified index in the input sequence.
389 389
      * @package YaLinqo\Pagination
390 390
      */
391 391
     public function skip ($count)
@@ -408,7 +408,7 @@  discard block
 block discarded – undo
408 408
      * <p>This method tests each element of source by using predicate and skips the element if the result is true. After the predicate function returns false for an element, that element and the remaining elements in source are yielded and there are no more invocations of predicate. If predicate returns true for all elements in the sequence, an empty sequence is returned.
409 409
      * <p>The {@link takeWhile} and skipWhile methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll.
410 410
      * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition.
411
-     * @return Enumerable A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
411
+     * @return EnumerablePagination A sequence that contains the elements from the input sequence starting at the first element in the linear series that does not pass the test specified by predicate.
412 412
      * @package YaLinqo\Pagination
413 413
      */
414 414
     public function skipWhile ($predicate)
@@ -432,7 +432,7 @@  discard block
 block discarded – undo
432 432
      * <p>Take enumerates source and yields elements until count elements have been yielded or source contains no more elements. If count is less than or equal to zero, source is not enumerated and an empty sequence is returned.
433 433
      * <p>The take and {@link skip} methods are functional complements. Given a sequence coll and an integer n, concatenating the results of coll->take(n) and coll->skip(n) yields the same sequence as coll.
434 434
      * @param int $count The number of elements to return.
435
-     * @return Enumerable A sequence that contains the specified number of elements from the start of the input sequence.
435
+     * @return EnumerablePagination A sequence that contains the specified number of elements from the start of the input sequence.
436 436
      * @package YaLinqo\Pagination
437 437
      */
438 438
     public function take ($count)
@@ -457,7 +457,7 @@  discard block
 block discarded – undo
457 457
      * <p>The takeWhile method tests each element of source by using predicate and yields the element if the result is true. Enumeration stops when the predicate function returns false for an element or when source contains no more elements.
458 458
      * <p>The takeWhile and {@link skipWhile} methods are functional complements. Given a sequence coll and a pure function p, concatenating the results of coll->takeWhile(p) and coll->skipWhile(p) yields the same sequence as coll.
459 459
      * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition.
460
-     * @return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
460
+     * @return EnumerablePagination A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
461 461
      * @package YaLinqo\Pagination
462 462
      */
463 463
     public function takeWhile ($predicate)
Please login to merge, or discard this patch.
Braces   +66 added lines, -44 removed lines patch added patch discarded remove patch
@@ -23,14 +23,16 @@  discard block
 block discarded – undo
23 23
         $it = $this->getIterator();
24 24
 
25 25
         if ($it instanceof \ArrayAccess) {
26
-            if (!$it->offsetExists($key))
27
-                throw new \UnexpectedValueException(Errors::NO_KEY);
26
+            if (!$it->offsetExists($key)) {
27
+                            throw new \UnexpectedValueException(Errors::NO_KEY);
28
+            }
28 29
             return $it->offsetGet($key);
29 30
         }
30 31
 
31 32
         foreach ($it as $k => $v) {
32
-            if ($k === $key)
33
-                return $v;
33
+            if ($k === $key) {
34
+                            return $v;
35
+            }
34 36
         }
35 37
         throw new \UnexpectedValueException(Errors::NO_KEY);
36 38
     }
@@ -49,12 +51,14 @@  discard block
 block discarded – undo
49 51
         /** @var $it \Iterator|\ArrayAccess */
50 52
         $it = $this->getIterator();
51 53
 
52
-        if ($it instanceof \ArrayAccess)
53
-            return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
54
+        if ($it instanceof \ArrayAccess) {
55
+                    return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
56
+        }
54 57
 
55 58
         foreach ($it as $k => $v) {
56
-            if ($k === $key)
57
-                return $v;
59
+            if ($k === $key) {
60
+                            return $v;
61
+            }
58 62
         }
59 63
         return $default;
60 64
     }
@@ -77,8 +81,9 @@  discard block
 block discarded – undo
77 81
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
78 82
 
79 83
         foreach ($this as $k => $v) {
80
-            if ($predicate($v, $k))
81
-                return $v;
84
+            if ($predicate($v, $k)) {
85
+                            return $v;
86
+            }
82 87
         }
83 88
         throw new \UnexpectedValueException(Errors::NO_MATCHES);
84 89
     }
@@ -100,8 +105,9 @@  discard block
 block discarded – undo
100 105
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
101 106
 
102 107
         foreach ($this as $k => $v) {
103
-            if ($predicate($v, $k))
104
-                return $v;
108
+            if ($predicate($v, $k)) {
109
+                            return $v;
110
+            }
105 111
         }
106 112
         return $default;
107 113
     }
@@ -123,8 +129,9 @@  discard block
 block discarded – undo
123 129
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
124 130
 
125 131
         foreach ($this as $k => $v) {
126
-            if ($predicate($v, $k))
127
-                return $v;
132
+            if ($predicate($v, $k)) {
133
+                            return $v;
134
+            }
128 135
         }
129 136
         return $fallback();
130 137
     }
@@ -154,8 +161,9 @@  discard block
 block discarded – undo
154 161
                 $value = $v;
155 162
             }
156 163
         }
157
-        if (!$found)
158
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
164
+        if (!$found) {
165
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
166
+        }
159 167
         return $value;
160 168
     }
161 169
 
@@ -234,14 +242,16 @@  discard block
 block discarded – undo
234 242
         $value = null;
235 243
         foreach ($this as $k => $v) {
236 244
             if ($predicate($v, $k)) {
237
-                if ($found)
238
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
245
+                if ($found) {
246
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
247
+                }
239 248
                 $found = true;
240 249
                 $value = $v;
241 250
             }
242 251
         }
243
-        if (!$found)
244
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
252
+        if (!$found) {
253
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
254
+        }
245 255
         return $value;
246 256
     }
247 257
 
@@ -266,8 +276,9 @@  discard block
 block discarded – undo
266 276
         $value = null;
267 277
         foreach ($this as $k => $v) {
268 278
             if ($predicate($v, $k)) {
269
-                if ($found)
270
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
279
+                if ($found) {
280
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
281
+                }
271 282
                 $found = true;
272 283
                 $value = $v;
273 284
             }
@@ -296,8 +307,9 @@  discard block
 block discarded – undo
296 307
         $value = null;
297 308
         foreach ($this as $k => $v) {
298 309
             if ($predicate($v, $k)) {
299
-                if ($found)
300
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
310
+                if ($found) {
311
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
312
+                }
301 313
                 $found = true;
302 314
                 $value = $v;
303 315
             }
@@ -316,8 +328,9 @@  discard block
 block discarded – undo
316 328
     public function indexOf ($value)
317 329
     {
318 330
         foreach ($this as $k => $v) {
319
-            if ($v === $value)
320
-                return $k;
331
+            if ($v === $value) {
332
+                            return $k;
333
+            }
321 334
         }
322 335
         return null; // not -1
323 336
     }
@@ -334,8 +347,9 @@  discard block
 block discarded – undo
334 347
     {
335 348
         $key = null;
336 349
         foreach ($this as $k => $v) {
337
-            if ($v === $value)
338
-                $key = $k;
350
+            if ($v === $value) {
351
+                            $key = $k;
352
+            }
339 353
         }
340 354
         return $key; // not -1
341 355
     }
@@ -353,8 +367,9 @@  discard block
 block discarded – undo
353 367
         $predicate = Utils::createLambda($predicate, 'v,k');
354 368
 
355 369
         foreach ($this as $k => $v) {
356
-            if ($predicate($v, $k))
357
-                return $k;
370
+            if ($predicate($v, $k)) {
371
+                            return $k;
372
+            }
358 373
         }
359 374
         return null; // not -1
360 375
     }
@@ -373,8 +388,9 @@  discard block
 block discarded – undo
373 388
 
374 389
         $key = null;
375 390
         foreach ($this as $k => $v) {
376
-            if ($predicate($v, $k))
377
-                $key = $k;
391
+            if ($predicate($v, $k)) {
392
+                            $key = $k;
393
+            }
378 394
         }
379 395
         return $key; // not -1
380 396
     }
@@ -393,8 +409,9 @@  discard block
 block discarded – undo
393 409
         return new self(function () use ($count) {
394 410
             $it = $this->getIterator();
395 411
             $it->rewind();
396
-            for ($i = 0; $i < $count && $it->valid(); ++$i)
397
-                $it->next();
412
+            for ($i = 0; $i < $count && $it->valid(); ++$i) {
413
+                            $it->next();
414
+            }
398 415
             while ($it->valid()) {
399 416
                 yield $it->key() => $it->current();
400 417
                 $it->next();
@@ -418,10 +435,12 @@  discard block
 block discarded – undo
418 435
         return new self(function () use ($predicate) {
419 436
             $yielding = false;
420 437
             foreach ($this as $k => $v) {
421
-                if (!$yielding && !$predicate($v, $k))
422
-                    $yielding = true;
423
-                if ($yielding)
424
-                    yield $k => $v;
438
+                if (!$yielding && !$predicate($v, $k)) {
439
+                                    $yielding = true;
440
+                }
441
+                if ($yielding) {
442
+                                    yield $k => $v;
443
+                }
425 444
             }
426 445
         });
427 446
     }
@@ -437,14 +456,16 @@  discard block
 block discarded – undo
437 456
      */
438 457
     public function take ($count)
439 458
     {
440
-        if ($count <= 0)
441
-            return new self(new \EmptyIterator, false);
459
+        if ($count <= 0) {
460
+                    return new self(new \EmptyIterator, false);
461
+        }
442 462
 
443 463
         return new self(function () use ($count) {
444 464
             foreach ($this as $k => $v) {
445 465
                 yield $k => $v;
446
-                if (--$count == 0)
447
-                    break;
466
+                if (--$count == 0) {
467
+                                    break;
468
+                }
448 469
             }
449 470
         });
450 471
     }
@@ -464,8 +485,9 @@  discard block
 block discarded – undo
464 485
 
465 486
         return new self(function () use ($predicate) {
466 487
             foreach ($this as $k => $v) {
467
-                if (!$predicate($v, $k))
468
-                    break;
488
+                if (!$predicate($v, $k)) {
489
+                                    break;
490
+                }
469 491
                 yield $k => $v;
470 492
             }
471 493
         });
Please login to merge, or discard this patch.
YaLinqo/Functions.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -142,7 +142,7 @@
 block discarded – undo
142 142
 
143 143
     /**
144 144
      * Increment function: returns incremental integers starting from 0.
145
-     * @return callable
145
+     * @return \Closure
146 146
      */
147 147
     public static function increment ()
148 148
     {
Please login to merge, or discard this patch.
Braces   +28 added lines, -24 removed lines patch added patch discarded remove patch
@@ -96,39 +96,43 @@
 block discarded – undo
96 96
         self::$blank = function () { };
97 97
 
98 98
         self::$compareStrict = function ($a, $b) {
99
-            if ($a === $b)
100
-                return 0;
101
-            elseif ($a > $b)
102
-                return 1;
103
-            else
104
-                return -1;
99
+            if ($a === $b) {
100
+                            return 0;
101
+            } elseif ($a > $b) {
102
+                            return 1;
103
+            } else {
104
+                            return -1;
105
+            }
105 106
         };
106 107
 
107 108
         self::$compareStrictReversed = function ($a, $b) {
108
-            if ($a === $b)
109
-                return 0;
110
-            elseif ($a > $b)
111
-                return -1;
112
-            else
113
-                return 1;
109
+            if ($a === $b) {
110
+                            return 0;
111
+            } elseif ($a > $b) {
112
+                            return -1;
113
+            } else {
114
+                            return 1;
115
+            }
114 116
         };
115 117
 
116 118
         self::$compareLoose = function ($a, $b) {
117
-            if ($a == $b)
118
-                return 0;
119
-            elseif ($a > $b)
120
-                return 1;
121
-            else
122
-                return -1;
119
+            if ($a == $b) {
120
+                            return 0;
121
+            } elseif ($a > $b) {
122
+                            return 1;
123
+            } else {
124
+                            return -1;
125
+            }
123 126
         };
124 127
 
125 128
         self::$compareLooseReversed = function ($a, $b) {
126
-            if ($a == $b)
127
-                return 0;
128
-            elseif ($a > $b)
129
-                return -1;
130
-            else
131
-                return 1;
129
+            if ($a == $b) {
130
+                            return 0;
131
+            } elseif ($a > $b) {
132
+                            return -1;
133
+            } else {
134
+                            return 1;
135
+            }
132 136
         };
133 137
 
134 138
         self::$compareInt = function ($a, $b) {
Please login to merge, or discard this patch.
YaLinqo/OrderedEnumerable.php 2 patches
Doc Comments   +7 added lines, -1 removed lines patch added patch discarded remove patch
@@ -67,7 +67,7 @@  discard block
 block discarded – undo
67 67
      * <p>Three methods are defined to extend the type OrderedEnumerable, which is the return type of this method. These three methods, namely {@link thenBy}, {@link thenByDescending} and {@link thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made.
68 68
      * <p>Because OrderedEnumerable inherits from {@link Enumerable}, you can call {@link Enumerable::orderBy orderBy}, {@link Enumerable::orderByDescending orderByDescending} or {@link Enumerable::orderByDir orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering.
69 69
      * <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used.
70
-     * @param int|bool $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value).
70
+     * @param boolean $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value).
71 71
      * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value.
72 72
      * @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags.
73 73
      * @return \YaLinqo\OrderedEnumerable
@@ -124,6 +124,9 @@  discard block
 block discarded – undo
124 124
         return $this->sortByMultipleFields($array, $canMultisort);
125 125
     }
126 126
 
127
+    /**
128
+     * @param boolean $canMultisort
129
+     */
127 130
     private function trySortBySingleField ($array, $canMultisort)
128 131
     {
129 132
         if ($this->parent !== null || $array === null) {
@@ -151,6 +154,9 @@  discard block
 block discarded – undo
151 154
         return new \ArrayIterator($array);
152 155
     }
153 156
 
157
+    /**
158
+     * @param boolean $canMultisort
159
+     */
154 160
     private function sortByMultipleFields ($array, $canMultisort)
155 161
     {
156 162
         $orders = [ ];
Please login to merge, or discard this patch.
Braces   +47 added lines, -38 removed lines patch added patch discarded remove patch
@@ -56,8 +56,10 @@  discard block
 block discarded – undo
56 56
     private function getSingleComparer ()
57 57
     {
58 58
         $comparer = $this->comparer;
59
-        if ($this->isReversed)
60
-            $comparer = function ($a, $b) use ($comparer) { return -$comparer($a, $b); };
59
+        if ($this->isReversed) {
60
+                    $comparer = function ($a, $b) use ($comparer) { return -$comparer($a, $b);
61
+        }
62
+        };
61 63
         return $comparer;
62 64
     }
63 65
 
@@ -118,8 +120,9 @@  discard block
 block discarded – undo
118 120
         $array = $this->source->tryGetArrayCopy();
119 121
 
120 122
         $it = $this->trySortBySingleField($array, $canMultisort);
121
-        if ($it !== null)
122
-            return $it;
123
+        if ($it !== null) {
124
+                    return $it;
125
+        }
123 126
 
124 127
         return $this->sortByMultipleFields($array, $canMultisort);
125 128
     }
@@ -128,24 +131,23 @@  discard block
 block discarded – undo
128 131
     {
129 132
         if ($this->parent !== null || $array === null) {
130 133
             return null;
131
-        }
132
-        else if ($this->keySelector === Functions::$value) {
133
-            if (!$canMultisort)
134
-                uasort($array, $this->getSingleComparer());
135
-            elseif ($this->sortOrder == SORT_ASC)
136
-                asort($array, $this->sortFlags);
137
-            else
138
-                arsort($array, $this->sortFlags);
139
-        }
140
-        elseif ($this->keySelector === Functions::$key) {
141
-            if ($canMultisort)
142
-                uksort($array, $this->getSingleComparer());
143
-            elseif ($this->sortOrder == SORT_ASC)
144
-                ksort($array, $this->sortFlags);
145
-            else
146
-                krsort($array, $this->sortFlags);
147
-        }
148
-        else {
134
+        } else if ($this->keySelector === Functions::$value) {
135
+            if (!$canMultisort) {
136
+                            uasort($array, $this->getSingleComparer());
137
+            } elseif ($this->sortOrder == SORT_ASC) {
138
+                            asort($array, $this->sortFlags);
139
+            } else {
140
+                            arsort($array, $this->sortFlags);
141
+            }
142
+        } elseif ($this->keySelector === Functions::$key) {
143
+            if ($canMultisort) {
144
+                            uksort($array, $this->getSingleComparer());
145
+            } elseif ($this->sortOrder == SORT_ASC) {
146
+                            ksort($array, $this->sortFlags);
147
+            } else {
148
+                            krsort($array, $this->sortFlags);
149
+            }
150
+        } else {
149 151
             return null;
150 152
         }
151 153
         return new \ArrayIterator($array);
@@ -156,14 +158,16 @@  discard block
 block discarded – undo
156 158
         $orders = [ ];
157 159
         for ($order = $this; $order !== null; $order = $order->parent) {
158 160
             $orders[] = $order;
159
-            if ($order->sortFlags === null)
160
-                $canMultisort = false;
161
+            if ($order->sortFlags === null) {
162
+                            $canMultisort = false;
163
+            }
161 164
         }
162 165
         $orders = array_reverse($orders);
163 166
 
164 167
         $it = $this->trySortArrayWithMultisort($array, $orders, $canMultisort);
165
-        if ($it !== null)
166
-            return $it;
168
+        if ($it !== null) {
169
+                    return $it;
170
+        }
167 171
 
168 172
         return $this->sortIterator($orders, $canMultisort);
169 173
     }
@@ -171,20 +175,23 @@  discard block
 block discarded – undo
171 175
     private function sortIterator ($orders, $canMultisort)
172 176
     {
173 177
         $enum = [ ];
174
-        if ($canMultisort)
175
-            $this->sortIteratorWithMultisort($enum, $orders);
176
-        else
177
-            $this->sortIteratorWithUsort($enum, $orders);
178
+        if ($canMultisort) {
179
+                    $this->sortIteratorWithMultisort($enum, $orders);
180
+        } else {
181
+                    $this->sortIteratorWithUsort($enum, $orders);
182
+        }
178 183
 
179
-        foreach ($enum as $pair)
180
-            yield $pair[0] => $pair[1];
184
+        foreach ($enum as $pair) {
185
+                    yield $pair[0] => $pair[1];
186
+        }
181 187
     }
182 188
 
183 189
     private function trySortArrayWithMultisort ($array, $orders, $canMultisort)
184 190
     {
185 191
         /** @var $order OrderedEnumerable */
186
-        if ($array === null || !$canMultisort)
187
-            return null;
192
+        if ($array === null || !$canMultisort) {
193
+                    return null;
194
+        }
188 195
 
189 196
         $args = [ ];
190 197
         foreach ($orders as $order) {
@@ -207,8 +214,9 @@  discard block
 block discarded – undo
207 214
     private function sortIteratorWithMultisort (&$enum, $orders)
208 215
     {
209 216
         /** @var $order OrderedEnumerable */
210
-        foreach ($this->source as $k => $v)
211
-            $enum[] = [ $k, $v ];
217
+        foreach ($this->source as $k => $v) {
218
+                    $enum[] = [ $k, $v ];
219
+        }
212 220
 
213 221
         $args = [ ];
214 222
         foreach ($orders as $order) {
@@ -245,8 +253,9 @@  discard block
 block discarded – undo
245 253
                 $order = $orders[$i];
246 254
                 $comparer = $order->comparer;
247 255
                 $diff = $comparer($a[$i + 2], $b[$i + 2]);
248
-                if ($diff != 0)
249
-                    return $order->isReversed ? -$diff : $diff;
256
+                if ($diff != 0) {
257
+                                    return $order->isReversed ? -$diff : $diff;
258
+                }
250 259
             }
251 260
             return 0;
252 261
         });
Please login to merge, or discard this patch.
YaLinqo/Enumerable.php 2 patches
Braces   +104 added lines, -76 removed lines patch added patch discarded remove patch
@@ -149,8 +149,9 @@  discard block
 block discarded – undo
149 149
         $selectorKey = Utils::createLambda($selectorKey, 'v,k', Functions::$key);
150 150
 
151 151
         return new self(function () use ($selectorValue, $selectorKey) {
152
-            foreach ($this as $k => $v)
153
-                yield $selectorKey($v, $k) => $selectorValue($v, $k);
152
+            foreach ($this as $k => $v) {
153
+                            yield $selectorKey($v, $k) => $selectorValue($v, $k);
154
+            }
154 155
         });
155 156
     }
156 157
 
@@ -174,13 +175,15 @@  discard block
 block discarded – undo
174 175
         $collectionSelector = Utils::createLambda($collectionSelector, 'v,k', Functions::$value);
175 176
         $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,k1,k2', Functions::$value);
176 177
         $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,k1,k2', false);
177
-        if ($resultSelectorKey === false)
178
-            $resultSelectorKey = Functions::increment();
178
+        if ($resultSelectorKey === false) {
179
+                    $resultSelectorKey = Functions::increment();
180
+        }
179 181
 
180 182
         return new self(function () use ($collectionSelector, $resultSelectorValue, $resultSelectorKey) {
181
-            foreach ($this as $ok => $ov)
182
-                foreach ($collectionSelector($ov, $ok) as $ik => $iv)
183
+            foreach ($this as $ok => $ov) {
184
+                            foreach ($collectionSelector($ov, $ok) as $ik => $iv)
183 185
                     yield $resultSelectorKey($iv, $ok, $ik) => $resultSelectorValue($iv, $ok, $ik);
186
+            }
184 187
         });
185 188
     }
186 189
 
@@ -196,9 +199,10 @@  discard block
 block discarded – undo
196 199
         $predicate = Utils::createLambda($predicate, 'v,k');
197 200
 
198 201
         return new self(function () use ($predicate) {
199
-            foreach ($this as $k => $v)
200
-                if ($predicate($v, $k))
202
+            foreach ($this as $k => $v) {
203
+                            if ($predicate($v, $k))
201 204
                     yield $k => $v;
205
+            }
202 206
         });
203 207
     }
204 208
 
@@ -325,9 +329,10 @@  discard block
 block discarded – undo
325 329
             $lookup = $inner->toLookup($innerKeySelector);
326 330
             foreach ($this as $ok => $ov) {
327 331
                 $key = $outerKeySelector($ov, $ok);
328
-                if (isset($lookup[$key]))
329
-                    foreach ($lookup[$key] as $iv)
332
+                if (isset($lookup[$key])) {
333
+                                    foreach ($lookup[$key] as $iv)
330 334
                         yield $resultSelectorKey($ov, $iv, $key) => $resultSelectorValue($ov, $iv, $key);
335
+                }
331 336
             }
332 337
         });
333 338
     }
@@ -385,20 +390,19 @@  discard block
 block discarded – undo
385 390
             foreach ($this as $k => $v) {
386 391
                 $result = $func($result, $v, $k);
387 392
             }
388
-        }
389
-        else {
393
+        } else {
390 394
             $assigned = false;
391 395
             foreach ($this as $k => $v) {
392 396
                 if ($assigned) {
393 397
                     $result = $func($result, $v, $k);
394
-                }
395
-                else {
398
+                } else {
396 399
                     $result = $v;
397 400
                     $assigned = true;
398 401
                 }
399 402
             }
400
-            if (!$assigned)
401
-                throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
403
+            if (!$assigned) {
404
+                            throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
405
+            }
402 406
         }
403 407
         return $result;
404 408
     }
@@ -425,13 +429,11 @@  discard block
 block discarded – undo
425 429
                 $result = $func($result, $v, $k);
426 430
                 $assigned = true;
427 431
             }
428
-        }
429
-        else {
432
+        } else {
430 433
             foreach ($this as $k => $v) {
431 434
                 if ($assigned) {
432 435
                     $result = $func($result, $v, $k);
433
-                }
434
-                else {
436
+                } else {
435 437
                     $result = $v;
436 438
                     $assigned = true;
437 439
                 }
@@ -460,8 +462,9 @@  discard block
 block discarded – undo
460 462
             $sum += $selector($v, $k);
461 463
             $count++;
462 464
         }
463
-        if ($count === 0)
464
-            throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
465
+        if ($count === 0) {
466
+                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
467
+        }
465 468
         return $sum / $count;
466 469
     }
467 470
 
@@ -479,15 +482,17 @@  discard block
 block discarded – undo
479 482
     {
480 483
         $it = $this->getIterator();
481 484
 
482
-        if ($it instanceof \Countable && $predicate === null)
483
-            return count($it);
485
+        if ($it instanceof \Countable && $predicate === null) {
486
+                    return count($it);
487
+        }
484 488
 
485 489
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$value);
486 490
         $count = 0;
487 491
 
488
-        foreach ($it as $k => $v)
489
-            if ($predicate($v, $k))
492
+        foreach ($it as $k => $v) {
493
+                    if ($predicate($v, $k))
490 494
                 $count++;
495
+        }
491 496
         return $count;
492 497
     }
493 498
 
@@ -512,8 +517,9 @@  discard block
 block discarded – undo
512 517
             $max = max($max, $selector($v, $k));
513 518
             $assigned = true;
514 519
         }
515
-        if (!$assigned)
516
-            throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
520
+        if (!$assigned) {
521
+                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
522
+        }
517 523
         return $max;
518 524
     }
519 525
 
@@ -534,8 +540,9 @@  discard block
 block discarded – undo
534 540
         $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict);
535 541
         $enum = $this;
536 542
 
537
-        if ($selector !== null)
538
-            $enum = $enum->select($selector);
543
+        if ($selector !== null) {
544
+                    $enum = $enum->select($selector);
545
+        }
539 546
         return $enum->aggregate(function ($a, $b) use ($comparer) { return $comparer($a, $b) > 0 ? $a : $b; });
540 547
     }
541 548
 
@@ -560,8 +567,9 @@  discard block
 block discarded – undo
560 567
             $min = min($min, $selector($v, $k));
561 568
             $assigned = true;
562 569
         }
563
-        if (!$assigned)
564
-            throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
570
+        if (!$assigned) {
571
+                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
572
+        }
565 573
         return $min;
566 574
     }
567 575
 
@@ -582,8 +590,9 @@  discard block
 block discarded – undo
582 590
         $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict);
583 591
         $enum = $this;
584 592
 
585
-        if ($selector !== null)
586
-            $enum = $enum->select($selector);
593
+        if ($selector !== null) {
594
+                    $enum = $enum->select($selector);
595
+        }
587 596
         return $enum->aggregate(function ($a, $b) use ($comparer) { return $comparer($a, $b) < 0 ? $a : $b; });
588 597
     }
589 598
 
@@ -603,8 +612,9 @@  discard block
 block discarded – undo
603 612
         $selector = Utils::createLambda($selector, 'v,k', Functions::$value);
604 613
 
605 614
         $sum = 0;
606
-        foreach ($this as $k => $v)
607
-            $sum += $selector($v, $k);
615
+        foreach ($this as $k => $v) {
616
+                    $sum += $selector($v, $k);
617
+        }
608 618
         return $sum;
609 619
     }
610 620
 
@@ -625,8 +635,9 @@  discard block
 block discarded – undo
625 635
         $predicate = Utils::createLambda($predicate, 'v,k');
626 636
 
627 637
         foreach ($this as $k => $v) {
628
-            if (!$predicate($v, $k))
629
-                return false;
638
+            if (!$predicate($v, $k)) {
639
+                            return false;
640
+            }
630 641
         }
631 642
         return true;
632 643
     }
@@ -647,15 +658,16 @@  discard block
 block discarded – undo
647 658
 
648 659
         if ($predicate) {
649 660
             foreach ($this as $k => $v) {
650
-                if ($predicate($v, $k))
651
-                    return true;
661
+                if ($predicate($v, $k)) {
662
+                                    return true;
663
+                }
652 664
             }
653 665
             return false;
654
-        }
655
-        else {
666
+        } else {
656 667
             $it = $this->getIterator();
657
-            if ($it instanceof \Countable)
658
-                return count($it) > 0;
668
+            if ($it instanceof \Countable) {
669
+                            return count($it) > 0;
670
+            }
659 671
             $it->rewind();
660 672
             return $it->valid();
661 673
         }
@@ -672,8 +684,9 @@  discard block
 block discarded – undo
672 684
     public function contains ($value)
673 685
     {
674 686
         foreach ($this as $v) {
675
-            if ($v === $value)
676
-                return true;
687
+            if ($v === $value) {
688
+                            return true;
689
+            }
677 690
         }
678 691
         return false;
679 692
     }
@@ -697,8 +710,9 @@  discard block
 block discarded – undo
697 710
             $set = [ ];
698 711
             foreach ($this as $k => $v) {
699 712
                 $key = $keySelector($v, $k);
700
-                if (isset($set[$key]))
701
-                    continue;
713
+                if (isset($set[$key])) {
714
+                                    continue;
715
+                }
702 716
                 $set[$key] = true;
703 717
                 yield $k => $v;
704 718
             }
@@ -730,8 +744,9 @@  discard block
 block discarded – undo
730 744
             }
731 745
             foreach ($this as $k => $v) {
732 746
                 $key = $keySelector($v, $k);
733
-                if (isset($set[$key]))
734
-                    continue;
747
+                if (isset($set[$key])) {
748
+                                    continue;
749
+                }
735 750
                 $set[$key] = true;
736 751
                 yield $k => $v;
737 752
             }
@@ -763,8 +778,9 @@  discard block
 block discarded – undo
763 778
             }
764 779
             foreach ($this as $k => $v) {
765 780
                 $key = $keySelector($v, $k);
766
-                if (!isset($set[$key]))
767
-                    continue;
781
+                if (!isset($set[$key])) {
782
+                                    continue;
783
+                }
768 784
                 unset($set[$key]);
769 785
                 yield $k => $v;
770 786
             }
@@ -793,15 +809,17 @@  discard block
 block discarded – undo
793 809
             $set = [ ];
794 810
             foreach ($this as $k => $v) {
795 811
                 $key = $keySelector($v, $k);
796
-                if (isset($set[$key]))
797
-                    continue;
812
+                if (isset($set[$key])) {
813
+                                    continue;
814
+                }
798 815
                 $set[$key] = true;
799 816
                 yield $k => $v;
800 817
             }
801 818
             foreach ($other as $k => $v) {
802 819
                 $key = $keySelector($v, $k);
803
-                if (isset($set[$key]))
804
-                    continue;
820
+                if (isset($set[$key])) {
821
+                                    continue;
822
+                }
805 823
                 $set[$key] = true;
806 824
                 yield $k => $v;
807 825
             }
@@ -825,12 +843,14 @@  discard block
 block discarded – undo
825 843
     {
826 844
         /** @var $it \Iterator|\ArrayIterator */
827 845
         $it = $this->getIterator();
828
-        if ($it instanceof \ArrayIterator)
829
-            return $it->getArrayCopy();
846
+        if ($it instanceof \ArrayIterator) {
847
+                    return $it->getArrayCopy();
848
+        }
830 849
 
831 850
         $array = [ ];
832
-        foreach ($it as $k => $v)
833
-            $array[$k] = $v;
851
+        foreach ($it as $k => $v) {
852
+                    $array[$k] = $v;
853
+        }
834 854
         return $array;
835 855
     }
836 856
 
@@ -857,8 +877,9 @@  discard block
 block discarded – undo
857 877
     protected function toArrayDeepProc ($enum)
858 878
     {
859 879
         $array = [ ];
860
-        foreach ($enum as $k => $v)
861
-            $array[$k] = $v instanceof \Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v;
880
+        foreach ($enum as $k => $v) {
881
+                    $array[$k] = $v instanceof \Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v;
882
+        }
862 883
         return $array;
863 884
     }
864 885
 
@@ -875,12 +896,14 @@  discard block
 block discarded – undo
875 896
     {
876 897
         /** @var $it \Iterator|\ArrayIterator */
877 898
         $it = $this->getIterator();
878
-        if ($it instanceof \ArrayIterator)
879
-            return array_values($it->getArrayCopy());
899
+        if ($it instanceof \ArrayIterator) {
900
+                    return array_values($it->getArrayCopy());
901
+        }
880 902
 
881 903
         $array = [ ];
882
-        foreach ($it as $v)
883
-            $array[] = $v;
904
+        foreach ($it as $v) {
905
+                    $array[] = $v;
906
+        }
884 907
         return $array;
885 908
     }
886 909
 
@@ -907,8 +930,9 @@  discard block
 block discarded – undo
907 930
     protected function toListDeepProc ($enum)
908 931
     {
909 932
         $array = [ ];
910
-        foreach ($enum as $v)
911
-            $array[] = $v instanceof \Traversable || is_array($v) ? $this->toListDeepProc($v) : $v;
933
+        foreach ($enum as $v) {
934
+                    $array[] = $v instanceof \Traversable || is_array($v) ? $this->toListDeepProc($v) : $v;
935
+        }
912 936
         return $array;
913 937
     }
914 938
 
@@ -927,8 +951,9 @@  discard block
 block discarded – undo
927 951
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
928 952
 
929 953
         $dic = [ ];
930
-        foreach ($this as $k => $v)
931
-            $dic[$keySelector($v, $k)] = $valueSelector($v, $k);
954
+        foreach ($this as $k => $v) {
955
+                    $dic[$keySelector($v, $k)] = $valueSelector($v, $k);
956
+        }
932 957
         return $dic;
933 958
     }
934 959
 
@@ -961,8 +986,9 @@  discard block
 block discarded – undo
961 986
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
962 987
 
963 988
         $lookup = [ ];
964
-        foreach ($this as $k => $v)
965
-            $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k);
989
+        foreach ($this as $k => $v) {
990
+                    $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k);
991
+        }
966 992
         return $lookup;
967 993
     }
968 994
 
@@ -1004,8 +1030,9 @@  discard block
 block discarded – undo
1004 1030
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
1005 1031
 
1006 1032
         $obj = new \stdClass();
1007
-        foreach ($this as $k => $v)
1008
-            $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k);
1033
+        foreach ($this as $k => $v) {
1034
+                    $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k);
1035
+        }
1009 1036
         return $obj;
1010 1037
     }
1011 1038
 
@@ -1062,8 +1089,9 @@  discard block
 block discarded – undo
1062 1089
     {
1063 1090
         $action = Utils::createLambda($action, 'v,k', Functions::$blank);
1064 1091
 
1065
-        foreach ($this as $k => $v)
1066
-            $action($v, $k);
1092
+        foreach ($this as $k => $v) {
1093
+                    $action($v, $k);
1094
+        }
1067 1095
     }
1068 1096
 
1069 1097
     /**
Please login to merge, or discard this patch.
Doc Comments   +4 added lines, -4 removed lines patch added patch discarded remove patch
@@ -34,7 +34,7 @@  discard block
 block discarded – undo
34 34
 
35 35
     /**
36 36
      * @internal
37
-     * @param \Closure|\Iterator $iterator
37
+     * @param \Closure $iterator
38 38
      * @param bool $isClosure
39 39
      */
40 40
     private function __construct ($iterator, $isClosure = true)
@@ -212,7 +212,7 @@  discard block
 block discarded – undo
212 212
      * <p>Three methods are defined to extend the type {@link OrderedEnumerable}, which is the return type of this method. These three methods, namely {@link OrderedEnumerable::thenBy thenBy}, {@link OrderedEnumerable::thenByDescending thenByDescending} and {@link OrderedEnumerable::thenByDir thenByDir}, enable you to specify additional sort criteria to sort a sequence. These methods also return an OrderedEnumerable, which means any number of consecutive calls to thenBy, thenByDescending or thenByDir can be made.
213 213
      * <p>Because OrderedEnumerable inherits from Enumerable, you can call {@link orderBy}, {@link orderByDescending} or {@link orderByDir} on the results of a call to orderBy, orderByDescending, orderByDir, thenBy, thenByDescending or thenByDir. Doing this introduces a new primary ordering that ignores the previously established ordering.
214 214
      * <p>This method performs an unstable sort; that is, if the keys of two elements are equal, the order of the elements is not preserved. In contrast, a stable sort preserves the order of elements that have the same key. Internally, {@link usort} is used.
215
-     * @param int|bool $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value).
215
+     * @param boolean $sortOrder A direction in which to order the elements: false or SORT_DESC for ascending (by increasing value), true or SORT_ASC for descending (by decreasing value).
216 216
      * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value.
217 217
      * @param callable|int|null $comparer {(a, b) ==> diff} Difference between a and b: &lt;0 if a&lt;b; 0 if a==b; &gt;0 if a&gt;b. Can also be a combination of SORT_ flags.
218 218
      * @return OrderedEnumerable
@@ -850,7 +850,7 @@  discard block
 block discarded – undo
850 850
 
851 851
     /**
852 852
      * Proc for {@link toArrayDeep}.
853
-     * @param $enum \Traversable Source sequence.
853
+     * @param Enumerable $enum \Traversable Source sequence.
854 854
      * @return array An array that contains the elements from the input sequence.
855 855
      * @package YaLinqo\Conversion
856 856
      */
@@ -900,7 +900,7 @@  discard block
 block discarded – undo
900 900
 
901 901
     /**
902 902
      * Proc for {@link toListDeep}.
903
-     * @param $enum \Traversable Source sequence.
903
+     * @param Enumerable $enum \Traversable Source sequence.
904 904
      * @return array An array that contains the elements from the input sequence.
905 905
      * @package YaLinqo\Conversion
906 906
      */
Please login to merge, or discard this patch.
YaLinqo/Utils.php 1 patch
Braces   +33 added lines, -26 removed lines patch added patch discarded remove patch
@@ -58,16 +58,20 @@  discard block
 block discarded – undo
58 58
     public static function createLambda ($closure, $closureArgs, $default = null)
59 59
     {
60 60
         if ($closure === null) {
61
-            if ($default === null)
62
-                throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
61
+            if ($default === null) {
62
+                            throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
63
+            }
63 64
             return $default;
64 65
         }
65
-        if ($closure instanceof \Closure)
66
-            return $closure;
67
-        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs)))
68
-            return $function;
69
-        if (is_callable($closure))
70
-            return $closure;
66
+        if ($closure instanceof \Closure) {
67
+                    return $closure;
68
+        }
69
+        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) {
70
+                    return $function;
71
+        }
72
+        if (is_callable($closure)) {
73
+                    return $closure;
74
+        }
71 75
         throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE);
72 76
     }
73 77
 
@@ -85,8 +89,7 @@  discard block
 block discarded – undo
85 89
         if ($closure === null) {
86 90
             $isReversed = false;
87 91
             return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict;
88
-        }
89
-        elseif (is_int($closure)) {
92
+        } elseif (is_int($closure)) {
90 93
             switch ($closure) {
91 94
                 case SORT_REGULAR:
92 95
                     return Functions::$compareStrict;
@@ -118,14 +121,16 @@  discard block
 block discarded – undo
118 121
      */
119 122
     public static function lambdaToSortFlagsAndOrder ($closure, &$sortOrder)
120 123
     {
121
-        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC)
122
-            $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
123
-        if (is_int($closure))
124
-            return $closure;
125
-        elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure]))
126
-            return self::$compareFunctionToSortFlags[$closure];
127
-        else
128
-            return null;
124
+        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) {
125
+                    $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
126
+        }
127
+        if (is_int($closure)) {
128
+                    return $closure;
129
+        } elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) {
130
+                    return self::$compareFunctionToSortFlags[$closure];
131
+        } else {
132
+                    return null;
133
+        }
129 134
     }
130 135
 
131 136
     /**
@@ -139,24 +144,26 @@  discard block
 block discarded – undo
139 144
     {
140 145
         $posDollar = strpos($closure, '$');
141 146
         if ($posDollar !== false) {
142
-            if (isset(self::$lambdaCache[$closure][$closureArgs]))
143
-                return self::$lambdaCache[$closure][$closureArgs];
147
+            if (isset(self::$lambdaCache[$closure][$closureArgs])) {
148
+                            return self::$lambdaCache[$closure][$closureArgs];
149
+            }
144 150
             $posArrow = strpos($closure, '==>', $posDollar);
145 151
             if ($posArrow !== false) {
146 152
                 $args = trim(substr($closure, 0, $posArrow), "() \r\n\t");
147 153
                 $code = substr($closure, $posArrow + 3);
148
-            }
149
-            else {
154
+            } else {
150 155
                 $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null';
151 156
                 $code = $closure;
152 157
             }
153 158
             $code = trim($code, " \r\n\t");
154
-            if (strlen($code) > 0 && $code[0] != '{')
155
-                $code = "return {$code};";
159
+            if (strlen($code) > 0 && $code[0] != '{') {
160
+                            $code = "return {$code};";
161
+            }
156 162
             $fun = @create_function($args, $code);
157 163
             // @codeCoverageIgnoreStart
158
-            if (!$fun)
159
-                throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
164
+            if (!$fun) {
165
+                            throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
166
+            }
160 167
             // @codeCoverageIgnoreEnd
161 168
             self::$lambdaCache[$closure][$closureArgs] = $fun;
162 169
             return $fun;
Please login to merge, or discard this patch.