GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Completed
Push — master ( c63ced...3ae448 )
by Alexander
01:39
created
YaLinqo/EnumerableGeneration.php 2 patches
Doc Comments   +12 added lines, -12 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
      * @param array|\Iterator|\IteratorAggregate|Enumerable $source Source sequence.
23 23
      * @throws \InvalidArgumentException If source is not array or Traversible or Enumerable.
24 24
      * @throws \UnexpectedValueException If source contains no elements (checked during enumeration).
25
-     * @return Enumerable Endless list of items repeating the source sequence.
25
+     * @return EnumerableGeneration Endless list of items repeating the source sequence.
26 26
      * @package YaLinqo\Generation
27 27
      */
28 28
     public static function cycle($source)
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
     /**
46 46
      * Returns an empty sequence.
47 47
      * <p><b>Syntax</b>: emptyEnum ()
48
-     * @return Enumerable
48
+     * @return EnumerableGeneration
49 49
      * @package YaLinqo\Generation
50 50
      */
51 51
     public static function emptyEnum()
@@ -94,7 +94,7 @@  discard block
 block discarded – undo
94 94
      * @param mixed $seedValue Initial state of the generator loop for values. Default: null.
95 95
      * @param callable|null $funcKey {(v, k) ==> key} State update function to run on key after every iteration of the generator loop. Default: increment.
96 96
      * @param mixed $seedKey Initial state of the generator loop ofr keys. Default: 0.
97
-     * @return Enumerable
97
+     * @return EnumerableGeneration
98 98
      * @package YaLinqo\Generation
99 99
      */
100 100
     public static function generate($funcValue, $seedValue = null, $funcKey = null, $seedKey = null)
@@ -121,7 +121,7 @@  discard block
 block discarded – undo
121 121
      * <p><b>Syntax</b>: toInfinity ([start [, step]])
122 122
      * @param int $start The first integer in the sequence. Default: 0.
123 123
      * @param int $step The difference between adjacent integers. Default: 1.
124
-     * @return Enumerable
124
+     * @return EnumerableGeneration
125 125
      * @package YaLinqo\Generation
126 126
      */
127 127
     public static function toInfinity(int $start = 0, int $step = 1)
@@ -139,7 +139,7 @@  discard block
 block discarded – undo
139 139
      * @param string $subject The input string.
140 140
      * @param string $pattern The pattern to search for, as a string.
141 141
      * @param int $flags Can be a combination of the following flags: PREG_PATTERN_ORDER, PREG_SET_ORDER, PREG_OFFSET_CAPTURE. Default: PREG_SET_ORDER.
142
-     * @return Enumerable
142
+     * @return EnumerableGeneration
143 143
      * @see preg_match_all
144 144
      * @package YaLinqo\Generation
145 145
      */
@@ -156,7 +156,7 @@  discard block
 block discarded – undo
156 156
      * <p><b>Syntax</b>: toNegativeInfinity ([start [, step]])
157 157
      * @param int $start The first integer in the sequence. Default: 0.
158 158
      * @param int $step The difference between adjacent integers. Default: 1.
159
-     * @return Enumerable
159
+     * @return EnumerableGeneration
160 160
      * @package YaLinqo\Generation
161 161
      */
162 162
     public static function toNegativeInfinity(int $start = 0, int $step = 1)
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
      * Returns a sequence that contains a single element with a specified value.
169 169
      * <p><b>Syntax</b>: returnEnum (element)
170 170
      * @param mixed $element The single element in the resulting sequence.
171
-     * @return Enumerable Observable sequence containing the single specified element.
171
+     * @return EnumerableGeneration Observable sequence containing the single specified element.
172 172
      * @package YaLinqo\Generation
173 173
      */
174 174
     public static function returnEnum($element)
@@ -184,7 +184,7 @@  discard block
 block discarded – undo
184 184
      * @param int $start The value of the first integer in the sequence.
185 185
      * @param int $count The number of integers to generate.
186 186
      * @param int $step The difference between adjacent integers. Default: 1.
187
-     * @return Enumerable A sequence that contains a range of integral numbers.
187
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
188 188
      * @package YaLinqo\Generation
189 189
      */
190 190
     public static function range(int $start, int $count, int $step = 1)
@@ -206,7 +206,7 @@  discard block
 block discarded – undo
206 206
      * @param int $start The value of the first integer in the sequence.
207 207
      * @param int $count The number of integers to generate.
208 208
      * @param int $step The difference between adjacent integers. Default: 1.
209
-     * @return Enumerable A sequence that contains a range of integral numbers.
209
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
210 210
      * @package YaLinqo\Generation
211 211
      */
212 212
     public static function rangeDown(int $start, int $count, int $step = 1)
@@ -223,7 +223,7 @@  discard block
 block discarded – undo
223 223
      * @param int $end The value of the last integer in the sequence (not included).
224 224
      * @param int $step The difference between adjacent integers. Default: 1.
225 225
      * @throws \InvalidArgumentException If step is not a positive number.
226
-     * @return Enumerable A sequence that contains a range of integral numbers.
226
+     * @return EnumerableGeneration A sequence that contains a range of integral numbers.
227 227
      * @package YaLinqo\Generation
228 228
      */
229 229
     public static function rangeTo(int $start, int $end, $step = 1)
@@ -252,7 +252,7 @@  discard block
 block discarded – undo
252 252
      * @param int $element The value to be repeated.
253 253
      * @param int $count The number of times to repeat the value in the generated sequence. Default: null.
254 254
      * @throws \InvalidArgumentException If count is less than 0.
255
-     * @return Enumerable A sequence that contains a repeated value.
255
+     * @return EnumerableGeneration A sequence that contains a repeated value.
256 256
      * @package YaLinqo\Generation
257 257
      */
258 258
     public static function repeat($element, $count = null)
@@ -271,7 +271,7 @@  discard block
 block discarded – undo
271 271
      * @param string $subject The input string.
272 272
      * @param string $pattern The pattern to search for, as a string.
273 273
      * @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.
274
-     * @return Enumerable
274
+     * @return EnumerableGeneration
275 275
      * @see preg_split
276 276
      * @package YaLinqo\Generation
277 277
      */
Please login to merge, or discard this patch.
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -36,8 +36,9 @@  discard block
 block discarded – undo
36 36
                     yield $v;
37 37
                     $isEmpty = false;
38 38
                 }
39
-                if ($isEmpty)
40
-                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
39
+                if ($isEmpty) {
40
+                                    throw new \UnexpectedValueException(Errors::NO_ELEMENTS);
41
+                }
41 42
             }
42 43
         });
43 44
     }
@@ -72,14 +73,15 @@  discard block
 block discarded – undo
72 73
     public static function from($source)
73 74
     {
74 75
         $it = null;
75
-        if ($source instanceof Enumerable)
76
-            return $source;
77
-        elseif (is_array($source))
78
-            $it = new \ArrayIterator($source);
79
-        elseif ($source instanceof \IteratorAggregate)
80
-            $it = $source->getIterator();
81
-        elseif ($source instanceof \Traversable)
82
-            $it = $source;
76
+        if ($source instanceof Enumerable) {
77
+                    return $source;
78
+        } elseif (is_array($source)) {
79
+                    $it = new \ArrayIterator($source);
80
+        } elseif ($source instanceof \IteratorAggregate) {
81
+                    $it = $source->getIterator();
82
+        } elseif ($source instanceof \Traversable) {
83
+                    $it = $source;
84
+        }
83 85
         if ($it !== null) {
84 86
             return new self($it, false);
85 87
         }
@@ -128,8 +130,9 @@  discard block
 block discarded – undo
128 130
     {
129 131
         return new self(function() use ($start, $step) {
130 132
             $value = $start - $step;
131
-            while (true)
132
-                yield $value += $step;
133
+            while (true) {
134
+                            yield $value += $step;
135
+            }
133 136
         });
134 137
     }
135 138
 
@@ -189,12 +192,14 @@  discard block
 block discarded – undo
189 192
      */
190 193
     public static function range(int $start, int $count, int $step = 1)
191 194
     {
192
-        if ($count <= 0)
193
-            return self::emptyEnum();
195
+        if ($count <= 0) {
196
+                    return self::emptyEnum();
197
+        }
194 198
         return new self(function() use ($start, $count, $step) {
195 199
             $value = $start - $step;
196
-            while ($count-- > 0)
197
-                yield $value += $step;
200
+            while ($count-- > 0) {
201
+                            yield $value += $step;
202
+            }
198 203
         });
199 204
     }
200 205
 
@@ -228,16 +233,18 @@  discard block
 block discarded – undo
228 233
      */
229 234
     public static function rangeTo(int $start, int $end, $step = 1)
230 235
     {
231
-        if ($step <= 0)
232
-            throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
236
+        if ($step <= 0) {
237
+                    throw new \InvalidArgumentException(Errors::STEP_NEGATIVE);
238
+        }
233 239
         return new self(function() use ($start, $end, $step) {
234 240
             if ($start <= $end) {
235
-                for ($i = $start; $i < $end; $i += $step)
236
-                    yield $i;
237
-            }
238
-            else {
239
-                for ($i = $start; $i > $end; $i -= $step)
240
-                    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
+                }
241 248
             }
242 249
         });
243 250
     }
@@ -257,11 +264,13 @@  discard block
 block discarded – undo
257 264
      */
258 265
     public static function repeat($element, $count = null)
259 266
     {
260
-        if ($count < 0)
261
-            throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
267
+        if ($count < 0) {
268
+                    throw new \InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
269
+        }
262 270
         return new self(function() use ($element, $count) {
263
-            for ($i = 0; $i < $count || $count === null; $i++)
264
-                yield $element;
271
+            for ($i = 0; $i < $count || $count === null; $i++) {
272
+                            yield $element;
273
+            }
265 274
         });
266 275
     }
267 276
 
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
@@ -394,7 +394,7 @@  discard block
 block discarded – undo
394 394
      * <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.
395 395
      * <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.
396 396
      * @param int $count The number of elements to skip before returning the remaining elements.
397
-     * @return Enumerable A sequence that contains the elements that occur after the specified index in the input sequence.
397
+     * @return EnumerablePagination A sequence that contains the elements that occur after the specified index in the input sequence.
398 398
      * @package YaLinqo\Pagination
399 399
      */
400 400
     public function skip(int $count)
@@ -417,7 +417,7 @@  discard block
 block discarded – undo
417 417
      * <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.
418 418
      * <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.
419 419
      * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition.
420
-     * @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.
420
+     * @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.
421 421
      * @package YaLinqo\Pagination
422 422
      */
423 423
     public function skipWhile($predicate)
@@ -441,7 +441,7 @@  discard block
 block discarded – undo
441 441
      * <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.
442 442
      * <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.
443 443
      * @param int $count The number of elements to return.
444
-     * @return Enumerable A sequence that contains the specified number of elements from the start of the input sequence.
444
+     * @return EnumerablePagination A sequence that contains the specified number of elements from the start of the input sequence.
445 445
      * @package YaLinqo\Pagination
446 446
      */
447 447
     public function take(int $count)
@@ -464,7 +464,7 @@  discard block
 block discarded – undo
464 464
      * <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.
465 465
      * <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.
466 466
      * @param callable $predicate {(v, k) ==> result} A function to test each element for a condition.
467
-     * @return Enumerable A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
467
+     * @return EnumerablePagination A sequence that contains the elements from the input sequence that occur before the element at which the test no longer passes.
468 468
      * @package YaLinqo\Pagination
469 469
      */
470 470
     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
@@ -32,14 +32,16 @@  discard block
 block discarded – undo
32 32
         $it = $this->getIterator();
33 33
 
34 34
         if ($it instanceof \ArrayAccess) {
35
-            if (!$it->offsetExists($key))
36
-                throw new \UnexpectedValueException(Errors::NO_KEY);
35
+            if (!$it->offsetExists($key)) {
36
+                            throw new \UnexpectedValueException(Errors::NO_KEY);
37
+            }
37 38
             return $it->offsetGet($key);
38 39
         }
39 40
 
40 41
         foreach ($it as $k => $v) {
41
-            if ($k === $key)
42
-                return $v;
42
+            if ($k === $key) {
43
+                            return $v;
44
+            }
43 45
         }
44 46
         throw new \UnexpectedValueException(Errors::NO_KEY);
45 47
     }
@@ -58,12 +60,14 @@  discard block
 block discarded – undo
58 60
         /** @var $it \Iterator|\ArrayAccess */
59 61
         $it = $this->getIterator();
60 62
 
61
-        if ($it instanceof \ArrayAccess)
62
-            return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
63
+        if ($it instanceof \ArrayAccess) {
64
+                    return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
65
+        }
63 66
 
64 67
         foreach ($it as $k => $v) {
65
-            if ($k === $key)
66
-                return $v;
68
+            if ($k === $key) {
69
+                            return $v;
70
+            }
67 71
         }
68 72
         return $default;
69 73
     }
@@ -86,8 +90,9 @@  discard block
 block discarded – undo
86 90
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
87 91
 
88 92
         foreach ($this as $k => $v) {
89
-            if ($predicate($v, $k))
90
-                return $v;
93
+            if ($predicate($v, $k)) {
94
+                            return $v;
95
+            }
91 96
         }
92 97
         throw new \UnexpectedValueException(Errors::NO_MATCHES);
93 98
     }
@@ -109,8 +114,9 @@  discard block
 block discarded – undo
109 114
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
110 115
 
111 116
         foreach ($this as $k => $v) {
112
-            if ($predicate($v, $k))
113
-                return $v;
117
+            if ($predicate($v, $k)) {
118
+                            return $v;
119
+            }
114 120
         }
115 121
         return $default;
116 122
     }
@@ -132,8 +138,9 @@  discard block
 block discarded – undo
132 138
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
133 139
 
134 140
         foreach ($this as $k => $v) {
135
-            if ($predicate($v, $k))
136
-                return $v;
141
+            if ($predicate($v, $k)) {
142
+                            return $v;
143
+            }
137 144
         }
138 145
         return $fallback();
139 146
     }
@@ -163,8 +170,9 @@  discard block
 block discarded – undo
163 170
                 $value = $v;
164 171
             }
165 172
         }
166
-        if (!$found)
167
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
173
+        if (!$found) {
174
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
175
+        }
168 176
         return $value;
169 177
     }
170 178
 
@@ -243,14 +251,16 @@  discard block
 block discarded – undo
243 251
         $value = null;
244 252
         foreach ($this as $k => $v) {
245 253
             if ($predicate($v, $k)) {
246
-                if ($found)
247
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
254
+                if ($found) {
255
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
256
+                }
248 257
                 $found = true;
249 258
                 $value = $v;
250 259
             }
251 260
         }
252
-        if (!$found)
253
-            throw new \UnexpectedValueException(Errors::NO_MATCHES);
261
+        if (!$found) {
262
+                    throw new \UnexpectedValueException(Errors::NO_MATCHES);
263
+        }
254 264
         return $value;
255 265
     }
256 266
 
@@ -275,8 +285,9 @@  discard block
 block discarded – undo
275 285
         $value = null;
276 286
         foreach ($this as $k => $v) {
277 287
             if ($predicate($v, $k)) {
278
-                if ($found)
279
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
288
+                if ($found) {
289
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
290
+                }
280 291
                 $found = true;
281 292
                 $value = $v;
282 293
             }
@@ -305,8 +316,9 @@  discard block
 block discarded – undo
305 316
         $value = null;
306 317
         foreach ($this as $k => $v) {
307 318
             if ($predicate($v, $k)) {
308
-                if ($found)
309
-                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
319
+                if ($found) {
320
+                                    throw new \UnexpectedValueException(Errors::MANY_MATCHES);
321
+                }
310 322
                 $found = true;
311 323
                 $value = $v;
312 324
             }
@@ -325,8 +337,9 @@  discard block
 block discarded – undo
325 337
     public function indexOf($value)
326 338
     {
327 339
         foreach ($this as $k => $v) {
328
-            if ($v === $value)
329
-                return $k;
340
+            if ($v === $value) {
341
+                            return $k;
342
+            }
330 343
         }
331 344
         return null; // not -1
332 345
     }
@@ -343,8 +356,9 @@  discard block
 block discarded – undo
343 356
     {
344 357
         $key = null;
345 358
         foreach ($this as $k => $v) {
346
-            if ($v === $value)
347
-                $key = $k;
359
+            if ($v === $value) {
360
+                            $key = $k;
361
+            }
348 362
         }
349 363
         return $key; // not -1
350 364
     }
@@ -362,8 +376,9 @@  discard block
 block discarded – undo
362 376
         $predicate = Utils::createLambda($predicate, 'v,k');
363 377
 
364 378
         foreach ($this as $k => $v) {
365
-            if ($predicate($v, $k))
366
-                return $k;
379
+            if ($predicate($v, $k)) {
380
+                            return $k;
381
+            }
367 382
         }
368 383
         return null; // not -1
369 384
     }
@@ -382,8 +397,9 @@  discard block
 block discarded – undo
382 397
 
383 398
         $key = null;
384 399
         foreach ($this as $k => $v) {
385
-            if ($predicate($v, $k))
386
-                $key = $k;
400
+            if ($predicate($v, $k)) {
401
+                            $key = $k;
402
+            }
387 403
         }
388 404
         return $key; // not -1
389 405
     }
@@ -402,8 +418,9 @@  discard block
 block discarded – undo
402 418
         return new self(function() use ($count) {
403 419
             $it = $this->getIterator();
404 420
             $it->rewind();
405
-            for ($i = 0; $i < $count && $it->valid(); ++$i)
406
-                $it->next();
421
+            for ($i = 0; $i < $count && $it->valid(); ++$i) {
422
+                            $it->next();
423
+            }
407 424
             while ($it->valid()) {
408 425
                 yield $it->key() => $it->current();
409 426
                 $it->next();
@@ -427,10 +444,12 @@  discard block
 block discarded – undo
427 444
         return new self(function() use ($predicate) {
428 445
             $yielding = false;
429 446
             foreach ($this as $k => $v) {
430
-                if (!$yielding && !$predicate($v, $k))
431
-                    $yielding = true;
432
-                if ($yielding)
433
-                    yield $k => $v;
447
+                if (!$yielding && !$predicate($v, $k)) {
448
+                                    $yielding = true;
449
+                }
450
+                if ($yielding) {
451
+                                    yield $k => $v;
452
+                }
434 453
             }
435 454
         });
436 455
     }
@@ -446,14 +465,16 @@  discard block
 block discarded – undo
446 465
      */
447 466
     public function take(int $count)
448 467
     {
449
-        if ($count <= 0)
450
-            return new self(new \EmptyIterator, false);
468
+        if ($count <= 0) {
469
+                    return new self(new \EmptyIterator, false);
470
+        }
451 471
 
452 472
         return new self(function() use ($count) {
453 473
             foreach ($this as $k => $v) {
454 474
                 yield $k => $v;
455
-                if (--$count == 0)
456
-                    break;
475
+                if (--$count == 0) {
476
+                                    break;
477
+                }
457 478
             }
458 479
         });
459 480
     }
@@ -473,8 +494,9 @@  discard block
 block discarded – undo
473 494
 
474 495
         return new self(function() use ($predicate) {
475 496
             foreach ($this as $k => $v) {
476
-                if (!$predicate($v, $k))
477
-                    break;
497
+                if (!$predicate($v, $k)) {
498
+                                    break;
499
+                }
478 500
                 yield $k => $v;
479 501
             }
480 502
         });
Please login to merge, or discard this patch.
YaLinqo/OrderedEnumerable.php 2 patches
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -65,7 +65,7 @@
 block discarded – undo
65 65
      * <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.
66 66
      * <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.
67 67
      * <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.
68
-     * @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).
68
+     * @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).
69 69
      * @param callable|null $keySelector {(v, k) ==> key} A function to extract a key from an element. Default: value.
70 70
      * @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.
71 71
      * @return \YaLinqo\OrderedEnumerable
Please login to merge, or discard this patch.
Braces   +47 added lines, -38 removed lines patch added patch discarded remove patch
@@ -54,8 +54,10 @@  discard block
 block discarded – undo
54 54
     private function getSingleComparer()
55 55
     {
56 56
         $comparer = $this->comparer;
57
-        if ($this->isReversed)
58
-            $comparer = function($a, $b) use ($comparer) { return -$comparer($a, $b); };
57
+        if ($this->isReversed) {
58
+                    $comparer = function($a, $b) use ($comparer) { return -$comparer($a, $b);
59
+        }
60
+        };
59 61
         return $comparer;
60 62
     }
61 63
 
@@ -116,8 +118,9 @@  discard block
 block discarded – undo
116 118
         $array = $this->source->tryGetArrayCopy();
117 119
 
118 120
         $it = $this->trySortBySingleField($array, $canMultisort);
119
-        if ($it !== null)
120
-            return $it;
121
+        if ($it !== null) {
122
+                    return $it;
123
+        }
121 124
 
122 125
         return $this->sortByMultipleFields($array, $canMultisort);
123 126
     }
@@ -126,24 +129,23 @@  discard block
 block discarded – undo
126 129
     {
127 130
         if ($this->parent !== null || $array === null) {
128 131
             return null;
129
-        }
130
-        elseif ($this->keySelector === Functions::$value) {
131
-            if (!$canMultisort)
132
-                uasort($array, $this->getSingleComparer());
133
-            elseif ($this->sortOrder == SORT_ASC)
134
-                asort($array, $this->sortFlags);
135
-            else
136
-                arsort($array, $this->sortFlags);
137
-        }
138
-        elseif ($this->keySelector === Functions::$key) {
139
-            if ($canMultisort)
140
-                uksort($array, $this->getSingleComparer());
141
-            elseif ($this->sortOrder == SORT_ASC)
142
-                ksort($array, $this->sortFlags);
143
-            else
144
-                krsort($array, $this->sortFlags);
145
-        }
146
-        else {
132
+        } elseif ($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 {
147 149
             return null;
148 150
         }
149 151
         return new \ArrayIterator($array);
@@ -154,14 +156,16 @@  discard block
 block discarded – undo
154 156
         $orders = [];
155 157
         for ($order = $this; $order !== null; $order = $order->parent) {
156 158
             $orders[] = $order;
157
-            if ($order->sortFlags === null)
158
-                $canMultisort = false;
159
+            if ($order->sortFlags === null) {
160
+                            $canMultisort = false;
161
+            }
159 162
         }
160 163
         $orders = array_reverse($orders);
161 164
 
162 165
         $it = $this->trySortArrayWithMultisort($array, $orders, $canMultisort);
163
-        if ($it !== null)
164
-            return $it;
166
+        if ($it !== null) {
167
+                    return $it;
168
+        }
165 169
 
166 170
         return $this->sortIterator($orders, $canMultisort);
167 171
     }
@@ -169,20 +173,23 @@  discard block
 block discarded – undo
169 173
     private function sortIterator(array $orders, bool $canMultisort)
170 174
     {
171 175
         $enum = [];
172
-        if ($canMultisort)
173
-            $this->sortIteratorWithMultisort($enum, $orders);
174
-        else
175
-            $this->sortIteratorWithUsort($enum, $orders);
176
+        if ($canMultisort) {
177
+                    $this->sortIteratorWithMultisort($enum, $orders);
178
+        } else {
179
+                    $this->sortIteratorWithUsort($enum, $orders);
180
+        }
176 181
 
177
-        foreach ($enum as $pair)
178
-            yield $pair[0] => $pair[1];
182
+        foreach ($enum as $pair) {
183
+                    yield $pair[0] => $pair[1];
184
+        }
179 185
     }
180 186
 
181 187
     private function trySortArrayWithMultisort($array, array $orders, bool $canMultisort)
182 188
     {
183 189
         /** @var $order OrderedEnumerable */
184
-        if ($array === null || !$canMultisort)
185
-            return null;
190
+        if ($array === null || !$canMultisort) {
191
+                    return null;
192
+        }
186 193
 
187 194
         $args = [];
188 195
         foreach ($orders as $order) {
@@ -205,8 +212,9 @@  discard block
 block discarded – undo
205 212
     private function sortIteratorWithMultisort(&$enum, array $orders)
206 213
     {
207 214
         /** @var $order OrderedEnumerable */
208
-        foreach ($this->source as $k => $v)
209
-            $enum[] = [ $k, $v ];
215
+        foreach ($this->source as $k => $v) {
216
+                    $enum[] = [ $k, $v ];
217
+        }
210 218
 
211 219
         $args = [];
212 220
         foreach ($orders as $order) {
@@ -243,8 +251,9 @@  discard block
 block discarded – undo
243 251
                 $order = $orders[$i];
244 252
                 $comparer = $order->comparer;
245 253
                 $diff = $comparer($a[$i + 2], $b[$i + 2]);
246
-                if ($diff != 0)
247
-                    return $order->isReversed ? -$diff : $diff;
254
+                if ($diff != 0) {
255
+                                    return $order->isReversed ? -$diff : $diff;
256
+                }
248 257
             }
249 258
             return 0;
250 259
         });
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
@@ -56,16 +56,20 @@  discard block
 block discarded – undo
56 56
     public static function createLambda($closure, string $closureArgs, $default = null)
57 57
     {
58 58
         if ($closure === null) {
59
-            if ($default === null)
60
-                throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
59
+            if ($default === null) {
60
+                            throw new \InvalidArgumentException(self::ERROR_CLOSURE_NULL);
61
+            }
61 62
             return $default;
62 63
         }
63
-        if ($closure instanceof \Closure)
64
-            return $closure;
65
-        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs)))
66
-            return $function;
67
-        if (is_callable($closure))
68
-            return $closure;
64
+        if ($closure instanceof \Closure) {
65
+                    return $closure;
66
+        }
67
+        if (is_string($closure) && ($function = self::createLambdaFromString($closure, $closureArgs))) {
68
+                    return $function;
69
+        }
70
+        if (is_callable($closure)) {
71
+                    return $closure;
72
+        }
69 73
         throw new \InvalidArgumentException(self::ERROR_CLOSURE_NOT_CALLABLE);
70 74
     }
71 75
 
@@ -83,8 +87,7 @@  discard block
 block discarded – undo
83 87
         if ($closure === null) {
84 88
             $isReversed = false;
85 89
             return $sortOrder === SORT_DESC ? Functions::$compareStrictReversed : Functions::$compareStrict;
86
-        }
87
-        elseif (is_int($closure)) {
90
+        } elseif (is_int($closure)) {
88 91
             switch ($closure) {
89 92
                 case SORT_REGULAR:
90 93
                     return Functions::$compareStrict;
@@ -116,14 +119,16 @@  discard block
 block discarded – undo
116 119
      */
117 120
     public static function lambdaToSortFlagsAndOrder($closure, &$sortOrder)
118 121
     {
119
-        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC)
120
-            $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
121
-        if (is_int($closure))
122
-            return $closure;
123
-        elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure]))
124
-            return self::$compareFunctionToSortFlags[$closure];
125
-        else
126
-            return null;
122
+        if ($sortOrder !== SORT_ASC && $sortOrder !== SORT_DESC) {
123
+                    $sortOrder = $sortOrder ? SORT_DESC : SORT_ASC;
124
+        }
125
+        if (is_int($closure)) {
126
+                    return $closure;
127
+        } elseif (($closure === null || is_string($closure)) && isset(self::$compareFunctionToSortFlags[$closure])) {
128
+                    return self::$compareFunctionToSortFlags[$closure];
129
+        } else {
130
+                    return null;
131
+        }
127 132
     }
128 133
 
129 134
     /**
@@ -137,24 +142,26 @@  discard block
 block discarded – undo
137 142
     {
138 143
         $posDollar = strpos($closure, '$');
139 144
         if ($posDollar !== false) {
140
-            if (isset(self::$lambdaCache[$closure][$closureArgs]))
141
-                return self::$lambdaCache[$closure][$closureArgs];
145
+            if (isset(self::$lambdaCache[$closure][$closureArgs])) {
146
+                            return self::$lambdaCache[$closure][$closureArgs];
147
+            }
142 148
             $posArrow = strpos($closure, '==>', $posDollar);
143 149
             if ($posArrow !== false) {
144 150
                 $args = trim(substr($closure, 0, $posArrow), "() \r\n\t");
145 151
                 $code = substr($closure, $posArrow + 3);
146
-            }
147
-            else {
152
+            } else {
148 153
                 $args = '$' . str_replace(',', '=null,$', $closureArgs) . '=null';
149 154
                 $code = $closure;
150 155
             }
151 156
             $code = trim($code, " \r\n\t");
152
-            if (strlen($code) > 0 && $code[0] != '{')
153
-                $code = "return {$code};";
157
+            if (strlen($code) > 0 && $code[0] != '{') {
158
+                            $code = "return {$code};";
159
+            }
154 160
             $fun = @create_function($args, $code);
155 161
             // @codeCoverageIgnoreStart
156
-            if (!$fun)
157
-                throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
162
+            if (!$fun) {
163
+                            throw new \InvalidArgumentException(self::ERROR_CANNOT_PARSE_LAMBDA);
164
+            }
158 165
             // @codeCoverageIgnoreEnd
159 166
             self::$lambdaCache[$closure][$closureArgs] = $fun;
160 167
             return $fun;
Please login to merge, or discard this patch.