Completed
Push — master ( 59583f...4a3d01 )
by Alexander
12:44
created
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   +69 added lines, -46 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,16 +456,19 @@  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
-            if ($count <= 0)
445
-                return;
464
+            if ($count <= 0) {
465
+                            return;
466
+            }
446 467
             foreach ($this as $k => $v) {
447 468
                 yield $k => $v;
448
-                if (--$count == 0)
449
-                    break;
469
+                if (--$count == 0) {
470
+                                    break;
471
+                }
450 472
             }
451 473
         });
452 474
     }
@@ -466,8 +488,9 @@  discard block
 block discarded – undo
466 488
 
467 489
         return new self(function () use ($predicate) {
468 490
             foreach ($this as $k => $v) {
469
-                if (!$predicate($v, $k))
470
-                    break;
491
+                if (!$predicate($v, $k)) {
492
+                                    break;
493
+                }
471 494
                 yield $k => $v;
472 495
             }
473 496
         });
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/Utils.php 1 patch
Braces   +33 added lines, -26 removed lines patch added patch discarded remove patch
@@ -55,16 +55,20 @@  discard block
 block discarded – undo
55 55
     public static function createLambda ($closure, $closureArgs, $default = null)
56 56
     {
57 57
         if ($closure === null) {
58
-            if ($default === null)
59
-                throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
58
+            if ($default === null) {
59
+                            throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
60
+            }
60 61
             return $default;
61 62
         }
62
-        if ($closure instanceof \Closure)
63
-            return $closure;
64
-        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs)))
65
-            return $function;
66
-        if (is_callable($closure))
67
-            return $closure;
63
+        if ($closure instanceof \Closure) {
64
+                    return $closure;
65
+        }
66
+        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) {
67
+                    return $function;
68
+        }
69
+        if (is_callable($closure)) {
70
+                    return $closure;
71
+        }
68 72
         throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE);
69 73
     }
70 74
 
@@ -82,8 +86,7 @@  discard block
 block discarded – undo
82 86
         if ($closure === null) {
83 87
             $isReversed = false;
84 88
             return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict;
85
-        }
86
-        elseif (is_int($closure)) {
89
+        } elseif (is_int($closure)) {
87 90
             switch ($closure) {
88 91
                 case SORT_REGULAR:
89 92
                     return Functions::$compareStrict;
@@ -115,14 +118,16 @@  discard block
 block discarded – undo
115 118
      */
116 119
     public static function lambdaToSortFlagsAndOrder ($closure, &$sortOrder)
117 120
     {
118
-        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC)
119
-            $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
120
-        if (is_int($closure))
121
-            return $closure;
122
-        elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure]))
123
-            return self::$compareFunctionToSortFlags[$closure];
124
-        else
125
-            return null;
121
+        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) {
122
+                    $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
123
+        }
124
+        if (is_int($closure)) {
125
+                    return $closure;
126
+        } elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) {
127
+                    return self::$compareFunctionToSortFlags[$closure];
128
+        } else {
129
+                    return null;
130
+        }
126 131
     }
127 132
 
128 133
     /**
@@ -136,23 +141,25 @@  discard block
 block discarded – undo
136 141
     {
137 142
         $posDollar = strpos($closure, '$');
138 143
         if ($posDollar !== false) {
139
-            if (isset(self::$lambdaCache[$closure][$closureArgs]))
140
-                return self::$lambdaCache[$closure][$closureArgs];
144
+            if (isset(self::$lambdaCache[$closure][$closureArgs])) {
145
+                            return self::$lambdaCache[$closure][$closureArgs];
146
+            }
141 147
             $posArrow = strpos($closure, '==>', $posDollar);
142 148
             if ($posArrow !== false) {
143 149
                 $args = trim(substr($closure, 0, $posArrow), "() \r\n\t");
144 150
                 $code = substr($closure, $posArrow + 3);
145
-            }
146
-            else {
151
+            } else {
147 152
                 $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null';
148 153
                 $code = $closure;
149 154
             }
150 155
             $code = trim($code, " \r\n\t");
151
-            if (strlen($code) > 0 && $code[0] != '{')
152
-                $code = "return {$code};";
156
+            if (strlen($code) > 0 && $code[0] != '{') {
157
+                            $code = "return {$code};";
158
+            }
153 159
             $fun = create_function($args, $code);
154
-            if (!$fun)
155
-                throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
160
+            if (!$fun) {
161
+                            throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
162
+            }
156 163
             self::$lambdaCache[$closure][$closureArgs] = $fun;
157 164
             return $fun;
158 165
         }
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/EnumerableGeneration.php 2 patches
Doc Comments   +15 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 ()
@@ -79,6 +79,9 @@  discard block
 block discarded – undo
79 79
         throw new \InvalidArgumentException('source must be array or Traversable.');
80 80
     }
81 81
 
82
+    /**
83
+     * @param \Traversable $source
84
+     */
82 85
     private static function fromTraversable ($source)
83 86
     {
84 87
         foreach ($source as $k => $v)
@@ -93,7 +96,7 @@  discard block
 block discarded – undo
93 96
      * @param mixed $seedValue Initial state of the generator loop for values. Default: null.
94 97
      * @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment.
95 98
      * @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0.
96
-     * @return Enumerable
99
+     * @return EnumerableGeneration
97 100
      * @package YaLinqo\Generation
98 101
      */
99 102
     public static function generate ($funcValue, $seedValue = null, $funcKey = null, $seedKey = null)
@@ -120,7 +123,7 @@  discard block
 block discarded – undo
120 123
      * <p><b>Syntax</b>: toInfinity ([start [, step]])
121 124
      * @param int $start The first integer in the sequence. Default: 0.
122 125
      * @param int $step The difference between adjacent integers. Default: 1.
123
-     * @return Enumerable
126
+     * @return EnumerableGeneration
124 127
      * @package YaLinqo\Generation
125 128
      */
126 129
     public static function toInfinity ($start = 0, $step = 1)
@@ -138,7 +141,7 @@  discard block
 block discarded – undo
138 141
      * @param string $subject The input string.
139 142
      * @param string $pattern The pattern to search for, as a string.
140 143
      * @param int $flags Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER.
141
-     * @return Enumerable
144
+     * @return EnumerableGeneration
142 145
      * @see preg_match_all
143 146
      * @package YaLinqo\Generation
144 147
      */
@@ -155,7 +158,7 @@  discard block
 block discarded – undo
155 158
      * <p><b>Syntax</b>: toNegativeInfinity ([start [, step]])
156 159
      * @param int $start The first integer in the sequence. Default: 0.
157 160
      * @param int $step The difference between adjacent integers. Default: 1.
158
-     * @return Enumerable
161
+     * @return EnumerableGeneration
159 162
      * @package YaLinqo\Generation
160 163
      */
161 164
     public static function toNegativeInfinity ($start = 0, $step = 1)
@@ -167,7 +170,7 @@  discard block
 block discarded – undo
167 170
      * Returns a sequence that contains a single element with a specified value.
168 171
      * <p><b>Syntax</b>: returnEnum (element)
169 172
      * @param mixed $element The single element in the resulting sequence.
170
-     * @return Enumerable Observable sequence containing the single specified element.
173
+     * @return EnumerableGeneration Observable sequence containing the single specified element.
171 174
      * @package YaLinqo\Generation
172 175
      */
173 176
     public static function returnEnum ($element)
@@ -183,7 +186,7 @@  discard block
 block discarded – undo
183 186
      * @param int $start The value of the first integer in the sequence.
184 187
      * @param int $count The number of integers to generate.
185 188
      * @param int $step The difference between adjacent integers. Default: 1.
186
-     * @return Enumerable A sequence that contains a range of integral numbers.
189
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
187 190
      * @package YaLinqo\Generation
188 191
      */
189 192
     public static function range ($start, $count, $step = 1)
@@ -205,7 +208,7 @@  discard block
 block discarded – undo
205 208
      * @param int $start The value of the first integer in the sequence.
206 209
      * @param int $count The number of integers to generate.
207 210
      * @param int $step The difference between adjacent integers. Default: 1.
208
-     * @return Enumerable A sequence that contains a range of integral numbers.
211
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
209 212
      * @package YaLinqo\Generation
210 213
      */
211 214
     public static function rangeDown ($start, $count, $step = 1)
@@ -222,7 +225,7 @@  discard block
 block discarded – undo
222 225
      * @param int $end The value of the last integer in the sequence (not included).
223 226
      * @param int $step The difference between adjacent integers. Default: 1.
224 227
      * @throws \InvalidArgumentException If step is not a positive number.
225
-     * @return Enumerable A sequence that contains a range of integral numbers.
228
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
226 229
      * @package YaLinqo\Generation
227 230
      */
228 231
     public static function rangeTo ($start, $end, $step = 1)
@@ -251,7 +254,7 @@  discard block
 block discarded – undo
251 254
      * @param int $element The value to be repeated.
252 255
      * @param int $count The number of times to repeat the value in the generated sequence. Default: null.
253 256
      * @throws \InvalidArgumentException If count is less than 0.
254
-     * @return Enumerable A sequence that contains a repeated value.
257
+     * @return EnumerableGeneration A sequence that contains a repeated value.
255 258
      * @package YaLinqo\Generation
256 259
      */
257 260
     public static function repeat ($element, $count = null)
@@ -270,7 +273,7 @@  discard block
 block discarded – undo
270 273
      * @param string $subject The input string.
271 274
      * @param string $pattern The pattern to search for, as a string.
272 275
      * @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.
273
-     * @return Enumerable
276
+     * @return EnumerableGeneration
274 277
      * @see preg_split
275 278
      * @package YaLinqo\Generation
276 279
      */
Please login to merge, or discard this patch.
Braces   +42 added lines, -32 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,16 +64,17 @@  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 \Iterator)
71
-            $it = $source;
72
-        elseif ($source instanceof \IteratorAggregate)
73
-            $it = $source->getIterator();
74
-        elseif ($source instanceof \Traversable)
75
-            $it = self::fromTraversable($source);
67
+        if ($source instanceof Enumerable) {
68
+                    return $source;
69
+        } else if (is_array($source)) {
70
+                    $it = new \ArrayIterator($source);
71
+        } elseif ($source instanceof \Iterator) {
72
+                    $it = $source;
73
+        } elseif ($source instanceof \IteratorAggregate) {
74
+                    $it = $source->getIterator();
75
+        } elseif ($source instanceof \Traversable) {
76
+                    $it = self::fromTraversable($source);
77
+        }
76 78
         if ($it !== null) {
77 79
             return new self($it, false);
78 80
         }
@@ -81,8 +83,9 @@  discard block
 block discarded – undo
81 83
 
82 84
     private static function fromTraversable ($source)
83 85
     {
84
-        foreach ($source as $k => $v)
85
-            yield $k => $v;
86
+        foreach ($source as $k => $v) {
87
+                    yield $k => $v;
88
+        }
86 89
     }
87 90
 
88 91
     /**
@@ -127,8 +130,9 @@  discard block
 block discarded – undo
127 130
     {
128 131
         return new self(function () use ($start, $step) {
129 132
             $value = $start - $step;
130
-            while (true)
131
-                yield $value += $step;
133
+            while (true) {
134
+                            yield $value += $step;
135
+            }
132 136
         });
133 137
     }
134 138
 
@@ -188,12 +192,14 @@  discard block
 block discarded – undo
188 192
      */
189 193
     public static function range ($start, $count, $step = 1)
190 194
     {
191
-        if ($count <= 0)
192
-            return self::emptyEnum();
195
+        if ($count <= 0) {
196
+                    return self::emptyEnum();
197
+        }
193 198
         return new self(function () use ($start, $count, $step) {
194 199
             $value = $start - $step;
195
-            while ($count-- > 0)
196
-                yield $value += $step;
200
+            while ($count-- > 0) {
201
+                            yield $value += $step;
202
+            }
197 203
         });
198 204
     }
199 205
 
@@ -227,16 +233,18 @@  discard block
 block discarded – undo
227 233
      */
228 234
     public static function rangeTo ($start, $end, $step = 1)
229 235
     {
230
-        if ($step <= 0)
231
-            throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
236
+        if ($step <= 0) {
237
+                    throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
238
+        }
232 239
         return new self(function () use ($start, $end, $step) {
233 240
             if ($start <= $end) {
234
-                for ($i = $start; $i < $end; $i += $step)
235
-                    yield $i;
236
-            }
237
-            else {
238
-                for ($i = $start; $i > $end; $i -= $step)
239
-                    yield $i;
241
+                for ($i = $start; $i < $end; $i += $step) {
242
+                                    yield $i;
243
+                }
244
+            } else {
245
+                for ($i = $start; $i > $end; $i -= $step) {
246
+                                    yield $i;
247
+                }
240 248
             }
241 249
         });
242 250
     }
@@ -256,11 +264,13 @@  discard block
 block discarded – undo
256 264
      */
257 265
     public static function repeat ($element, $count = null)
258 266
     {
259
-        if ($count < 0)
260
-            throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
267
+        if ($count < 0) {
268
+                    throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
269
+        }
261 270
         return new self(function () use ($element, $count) {
262
-            for ($i = 0; $i < $count || $count === null; $i++)
263
-                yield $element;
271
+            for ($i = 0; $i < $count || $count === null; $i++) {
272
+                            yield $element;
273
+            }
264 274
         });
265 275
     }
266 276
 
Please login to merge, or discard this patch.