Completed
Push — master ( 793880...96f8de )
by Alexander
15s
created
YaLinqo/Enumerable.php 2 patches
Spacing   +7 added lines, -7 removed lines patch added patch discarded remove patch
@@ -79,22 +79,22 @@  discard block
 block discarded – undo
79 79
     {
80 80
         switch ($type) {
81 81
             case 'array':
82
-                return $this->select(function($v) { return (array)$v; });
82
+                return $this->select(function($v) { return (array) $v; });
83 83
             case 'int':
84 84
             case 'integer':
85 85
             case 'long':
86
-                return $this->select(function($v) { return (int)$v; });
86
+                return $this->select(function($v) { return (int) $v; });
87 87
             case 'float':
88 88
             case 'real':
89 89
             case 'double':
90
-                return $this->select(function($v) { return (float)$v; });
90
+                return $this->select(function($v) { return (float) $v; });
91 91
             case 'null':
92 92
             case 'unset':
93 93
                 return $this->select(function() { return null; });
94 94
             case 'object':
95
-                return $this->select(function($v) { return (object)$v; });
95
+                return $this->select(function($v) { return (object) $v; });
96 96
             case 'string':
97
-                return $this->select(function($v) { return (string)$v; });
97
+                return $this->select(function($v) { return (string) $v; });
98 98
             default:
99 99
                 throw new InvalidArgumentException(Errors::UNSUPPORTED_BUILTIN_TYPE);
100 100
         }
@@ -289,7 +289,7 @@  discard block
 block discarded – undo
289 289
         $inner = self::from($inner);
290 290
         $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key);
291 291
         $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key);
292
-        $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,e,k', function($v, $e, $k) { return [ $v, $e ]; });
292
+        $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,e,k', function($v, $e, $k) { return [$v, $e]; });
293 293
         $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,e,k', function($v, $e, $k) { return $k; });
294 294
 
295 295
         return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) {
@@ -323,7 +323,7 @@  discard block
 block discarded – undo
323 323
         $inner = self::from($inner);
324 324
         $outerKeySelector = Utils::createLambda($outerKeySelector, 'v,k', Functions::$key);
325 325
         $innerKeySelector = Utils::createLambda($innerKeySelector, 'v,k', Functions::$key);
326
-        $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v1,v2,k', function($v1, $v2, $k) { return [ $v1, $v2 ]; });
326
+        $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v1,v2,k', function($v1, $v2, $k) { return [$v1, $v2]; });
327 327
         $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v1,v2,k', function($v1, $v2, $k) { return $k; });
328 328
 
329 329
         return new self(function() use ($inner, $outerKeySelector, $innerKeySelector, $resultSelectorValue, $resultSelectorKey) {
Please login to merge, or discard this patch.
Braces   +107 added lines, -78 removed lines patch added patch discarded remove patch
@@ -154,8 +154,9 @@  discard block
 block discarded – undo
154 154
         $selectorKey = Utils::createLambda($selectorKey, 'v,k', Functions::$key);
155 155
 
156 156
         return new self(function() use ($selectorValue, $selectorKey) {
157
-            foreach ($this as $k => $v)
158
-                yield $selectorKey($v, $k) => $selectorValue($v, $k);
157
+            foreach ($this as $k => $v) {
158
+                            yield $selectorKey($v, $k) => $selectorValue($v, $k);
159
+            }
159 160
         });
160 161
     }
161 162
 
@@ -179,13 +180,15 @@  discard block
 block discarded – undo
179 180
         $collectionSelector = Utils::createLambda($collectionSelector, 'v,k', Functions::$value);
180 181
         $resultSelectorValue = Utils::createLambda($resultSelectorValue, 'v,k1,k2', Functions::$value);
181 182
         $resultSelectorKey = Utils::createLambda($resultSelectorKey, 'v,k1,k2', false);
182
-        if ($resultSelectorKey === false)
183
-            $resultSelectorKey = Functions::increment();
183
+        if ($resultSelectorKey === false) {
184
+                    $resultSelectorKey = Functions::increment();
185
+        }
184 186
 
185 187
         return new self(function() use ($collectionSelector, $resultSelectorValue, $resultSelectorKey) {
186
-            foreach ($this as $ok => $ov)
187
-                foreach ($collectionSelector($ov, $ok) as $ik => $iv)
188
+            foreach ($this as $ok => $ov) {
189
+                            foreach ($collectionSelector($ov, $ok) as $ik => $iv)
188 190
                     yield $resultSelectorKey($iv, $ok, $ik) => $resultSelectorValue($iv, $ok, $ik);
191
+            }
189 192
         });
190 193
     }
191 194
 
@@ -201,9 +204,10 @@  discard block
 block discarded – undo
201 204
         $predicate = Utils::createLambda($predicate, 'v,k');
202 205
 
203 206
         return new self(function() use ($predicate) {
204
-            foreach ($this as $k => $v)
205
-                if ($predicate($v, $k))
207
+            foreach ($this as $k => $v) {
208
+                            if ($predicate($v, $k))
206 209
                     yield $k => $v;
210
+            }
207 211
         });
208 212
     }
209 213
 
@@ -330,9 +334,10 @@  discard block
 block discarded – undo
330 334
             $lookup = $inner->toLookup($innerKeySelector);
331 335
             foreach ($this as $ok => $ov) {
332 336
                 $key = $outerKeySelector($ov, $ok);
333
-                if (isset($lookup[$key]))
334
-                    foreach ($lookup[$key] as $iv)
337
+                if (isset($lookup[$key])) {
338
+                                    foreach ($lookup[$key] as $iv)
335 339
                         yield $resultSelectorKey($ov, $iv, $key) => $resultSelectorValue($ov, $iv, $key);
340
+                }
336 341
             }
337 342
         });
338 343
     }
@@ -391,20 +396,19 @@  discard block
 block discarded – undo
391 396
             foreach ($this as $k => $v) {
392 397
                 $result = $func($result, $v, $k);
393 398
             }
394
-        }
395
-        else {
399
+        } else {
396 400
             $assigned = false;
397 401
             foreach ($this as $k => $v) {
398 402
                 if ($assigned) {
399 403
                     $result = $func($result, $v, $k);
400
-                }
401
-                else {
404
+                } else {
402 405
                     $result = $v;
403 406
                     $assigned = true;
404 407
                 }
405 408
             }
406
-            if (!$assigned)
407
-                throw new UnexpectedValueException(Errors::NO_ELEMENTS);
409
+            if (!$assigned) {
410
+                            throw new UnexpectedValueException(Errors::NO_ELEMENTS);
411
+            }
408 412
         }
409 413
         return $result;
410 414
     }
@@ -431,13 +435,11 @@  discard block
 block discarded – undo
431 435
                 $result = $func($result, $v, $k);
432 436
                 $assigned = true;
433 437
             }
434
-        }
435
-        else {
438
+        } else {
436 439
             foreach ($this as $k => $v) {
437 440
                 if ($assigned) {
438 441
                     $result = $func($result, $v, $k);
439
-                }
440
-                else {
442
+                } else {
441 443
                     $result = $v;
442 444
                     $assigned = true;
443 445
                 }
@@ -466,8 +468,9 @@  discard block
 block discarded – undo
466 468
             $sum += $selector($v, $k);
467 469
             $count++;
468 470
         }
469
-        if ($count === 0)
470
-            throw new UnexpectedValueException(Errors::NO_ELEMENTS);
471
+        if ($count === 0) {
472
+                    throw new UnexpectedValueException(Errors::NO_ELEMENTS);
473
+        }
471 474
         return $sum / $count;
472 475
     }
473 476
 
@@ -486,15 +489,17 @@  discard block
 block discarded – undo
486 489
     {
487 490
         $it = $this->getIterator();
488 491
 
489
-        if ($it instanceof Countable && $predicate === null)
490
-            return count($it);
492
+        if ($it instanceof Countable && $predicate === null) {
493
+                    return count($it);
494
+        }
491 495
 
492 496
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$value);
493 497
         $count = 0;
494 498
 
495
-        foreach ($it as $k => $v)
496
-            if ($predicate($v, $k))
499
+        foreach ($it as $k => $v) {
500
+                    if ($predicate($v, $k))
497 501
                 $count++;
502
+        }
498 503
         return $count;
499 504
     }
500 505
 
@@ -519,8 +524,9 @@  discard block
 block discarded – undo
519 524
             $max = max($max, $selector($v, $k));
520 525
             $assigned = true;
521 526
         }
522
-        if (!$assigned)
523
-            throw new UnexpectedValueException(Errors::NO_ELEMENTS);
527
+        if (!$assigned) {
528
+                    throw new UnexpectedValueException(Errors::NO_ELEMENTS);
529
+        }
524 530
         return $max;
525 531
     }
526 532
 
@@ -541,8 +547,9 @@  discard block
 block discarded – undo
541 547
         $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict);
542 548
         $enum = $this;
543 549
 
544
-        if ($selector !== null)
545
-            $enum = $enum->select($selector);
550
+        if ($selector !== null) {
551
+                    $enum = $enum->select($selector);
552
+        }
546 553
         return $enum->aggregate(function($a, $b) use ($comparer) { return $comparer($a, $b) > 0 ? $a : $b; });
547 554
     }
548 555
 
@@ -567,8 +574,9 @@  discard block
 block discarded – undo
567 574
             $min = min($min, $selector($v, $k));
568 575
             $assigned = true;
569 576
         }
570
-        if (!$assigned)
571
-            throw new UnexpectedValueException(Errors::NO_ELEMENTS);
577
+        if (!$assigned) {
578
+                    throw new UnexpectedValueException(Errors::NO_ELEMENTS);
579
+        }
572 580
         return $min;
573 581
     }
574 582
 
@@ -589,8 +597,9 @@  discard block
 block discarded – undo
589 597
         $comparer = Utils::createLambda($comparer, 'a,b', Functions::$compareStrict);
590 598
         $enum = $this;
591 599
 
592
-        if ($selector !== null)
593
-            $enum = $enum->select($selector);
600
+        if ($selector !== null) {
601
+                    $enum = $enum->select($selector);
602
+        }
594 603
         return $enum->aggregate(function($a, $b) use ($comparer) { return $comparer($a, $b) < 0 ? $a : $b; });
595 604
     }
596 605
 
@@ -610,8 +619,9 @@  discard block
 block discarded – undo
610 619
         $selector = Utils::createLambda($selector, 'v,k', Functions::$value);
611 620
 
612 621
         $sum = 0;
613
-        foreach ($this as $k => $v)
614
-            $sum += $selector($v, $k);
622
+        foreach ($this as $k => $v) {
623
+                    $sum += $selector($v, $k);
624
+        }
615 625
         return $sum;
616 626
     }
617 627
 
@@ -632,8 +642,9 @@  discard block
 block discarded – undo
632 642
         $predicate = Utils::createLambda($predicate, 'v,k');
633 643
 
634 644
         foreach ($this as $k => $v) {
635
-            if (!$predicate($v, $k))
636
-                return false;
645
+            if (!$predicate($v, $k)) {
646
+                            return false;
647
+            }
637 648
         }
638 649
         return true;
639 650
     }
@@ -655,15 +666,16 @@  discard block
 block discarded – undo
655 666
 
656 667
         if ($predicate) {
657 668
             foreach ($this as $k => $v) {
658
-                if ($predicate($v, $k))
659
-                    return true;
669
+                if ($predicate($v, $k)) {
670
+                                    return true;
671
+                }
660 672
             }
661 673
             return false;
662
-        }
663
-        else {
674
+        } else {
664 675
             $it = $this->getIterator();
665
-            if ($it instanceof Countable)
666
-                return count($it) > 0;
676
+            if ($it instanceof Countable) {
677
+                            return count($it) > 0;
678
+            }
667 679
             $it->rewind();
668 680
             return $it->valid();
669 681
         }
@@ -718,8 +730,9 @@  discard block
 block discarded – undo
718 730
     public function contains($value): bool
719 731
     {
720 732
         foreach ($this as $v) {
721
-            if ($v === $value)
722
-                return true;
733
+            if ($v === $value) {
734
+                            return true;
735
+            }
723 736
         }
724 737
         return false;
725 738
     }
@@ -743,8 +756,9 @@  discard block
 block discarded – undo
743 756
             $set = [];
744 757
             foreach ($this as $k => $v) {
745 758
                 $key = $keySelector($v, $k);
746
-                if (isset($set[$key]))
747
-                    continue;
759
+                if (isset($set[$key])) {
760
+                                    continue;
761
+                }
748 762
                 $set[$key] = true;
749 763
                 yield $k => $v;
750 764
             }
@@ -777,8 +791,9 @@  discard block
 block discarded – undo
777 791
             }
778 792
             foreach ($this as $k => $v) {
779 793
                 $key = $keySelector($v, $k);
780
-                if (isset($set[$key]))
781
-                    continue;
794
+                if (isset($set[$key])) {
795
+                                    continue;
796
+                }
782 797
                 $set[$key] = true;
783 798
                 yield $k => $v;
784 799
             }
@@ -811,8 +826,9 @@  discard block
 block discarded – undo
811 826
             }
812 827
             foreach ($this as $k => $v) {
813 828
                 $key = $keySelector($v, $k);
814
-                if (!isset($set[$key]))
815
-                    continue;
829
+                if (!isset($set[$key])) {
830
+                                    continue;
831
+                }
816 832
                 unset($set[$key]);
817 833
                 yield $k => $v;
818 834
             }
@@ -861,15 +877,17 @@  discard block
 block discarded – undo
861 877
             $set = [];
862 878
             foreach ($this as $k => $v) {
863 879
                 $key = $keySelector($v, $k);
864
-                if (isset($set[$key]))
865
-                    continue;
880
+                if (isset($set[$key])) {
881
+                                    continue;
882
+                }
866 883
                 $set[$key] = true;
867 884
                 yield $k => $v;
868 885
             }
869 886
             foreach ($other as $k => $v) {
870 887
                 $key = $keySelector($v, $k);
871
-                if (isset($set[$key]))
872
-                    continue;
888
+                if (isset($set[$key])) {
889
+                                    continue;
890
+                }
873 891
                 $set[$key] = true;
874 892
                 yield $k => $v;
875 893
             }
@@ -894,12 +912,14 @@  discard block
 block discarded – undo
894 912
     {
895 913
         /** @var $it Iterator|ArrayIterator */
896 914
         $it = $this->getIterator();
897
-        if ($it instanceof ArrayIterator)
898
-            return $it->getArrayCopy();
915
+        if ($it instanceof ArrayIterator) {
916
+                    return $it->getArrayCopy();
917
+        }
899 918
 
900 919
         $array = [];
901
-        foreach ($it as $k => $v)
902
-            $array[$k] = $v;
920
+        foreach ($it as $k => $v) {
921
+                    $array[$k] = $v;
922
+        }
903 923
         return $array;
904 924
     }
905 925
 
@@ -926,8 +946,9 @@  discard block
 block discarded – undo
926 946
     protected function toArrayDeepProc($enum): array
927 947
     {
928 948
         $array = [];
929
-        foreach ($enum as $k => $v)
930
-            $array[$k ?? ''] = $v instanceof Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v;
949
+        foreach ($enum as $k => $v) {
950
+                    $array[$k ?? ''] = $v instanceof Traversable || is_array($v) ? $this->toArrayDeepProc($v) : $v;
951
+        }
931 952
         return $array;
932 953
     }
933 954
 
@@ -945,12 +966,14 @@  discard block
 block discarded – undo
945 966
     {
946 967
         /** @var $it Iterator|ArrayIterator */
947 968
         $it = $this->getIterator();
948
-        if ($it instanceof ArrayIterator)
949
-            return array_values($it->getArrayCopy());
969
+        if ($it instanceof ArrayIterator) {
970
+                    return array_values($it->getArrayCopy());
971
+        }
950 972
 
951 973
         $array = [];
952
-        foreach ($it as $v)
953
-            $array[] = $v;
974
+        foreach ($it as $v) {
975
+                    $array[] = $v;
976
+        }
954 977
         return $array;
955 978
     }
956 979
 
@@ -977,8 +1000,9 @@  discard block
 block discarded – undo
977 1000
     protected function toListDeepProc($enum): array
978 1001
     {
979 1002
         $array = [];
980
-        foreach ($enum as $v)
981
-            $array[] = $v instanceof Traversable || is_array($v) ? $this->toListDeepProc($v) : $v;
1003
+        foreach ($enum as $v) {
1004
+                    $array[] = $v instanceof Traversable || is_array($v) ? $this->toListDeepProc($v) : $v;
1005
+        }
982 1006
         return $array;
983 1007
     }
984 1008
 
@@ -997,8 +1021,9 @@  discard block
 block discarded – undo
997 1021
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
998 1022
 
999 1023
         $dic = [];
1000
-        foreach ($this as $k => $v)
1001
-            $dic[$keySelector($v, $k)] = $valueSelector($v, $k);
1024
+        foreach ($this as $k => $v) {
1025
+                    $dic[$keySelector($v, $k)] = $valueSelector($v, $k);
1026
+        }
1002 1027
         return $dic;
1003 1028
     }
1004 1029
 
@@ -1015,8 +1040,9 @@  discard block
 block discarded – undo
1015 1040
     public function toJSON(int $options = 0): string
1016 1041
     {
1017 1042
         $result = json_encode($this->toArrayDeep(), $options);
1018
-        if ($result === false)
1019
-            throw new UnexpectedValueException(json_last_error_msg());
1043
+        if ($result === false) {
1044
+                    throw new UnexpectedValueException(json_last_error_msg());
1045
+        }
1020 1046
         return $result;
1021 1047
     }
1022 1048
 
@@ -1035,8 +1061,9 @@  discard block
 block discarded – undo
1035 1061
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
1036 1062
 
1037 1063
         $lookup = [];
1038
-        foreach ($this as $k => $v)
1039
-            $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k);
1064
+        foreach ($this as $k => $v) {
1065
+                    $lookup[$keySelector($v, $k)][] = $valueSelector($v, $k);
1066
+        }
1040 1067
         return $lookup;
1041 1068
     }
1042 1069
 
@@ -1078,8 +1105,9 @@  discard block
 block discarded – undo
1078 1105
         $valueSelector = Utils::createLambda($valueSelector, 'v,k', Functions::$value);
1079 1106
 
1080 1107
         $obj = new stdClass();
1081
-        foreach ($this as $k => $v)
1082
-            $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k);
1108
+        foreach ($this as $k => $v) {
1109
+                    $obj->{$propertySelector($v, $k)} = $valueSelector($v, $k);
1110
+        }
1083 1111
         return $obj;
1084 1112
     }
1085 1113
 
@@ -1149,8 +1177,9 @@  discard block
 block discarded – undo
1149 1177
     {
1150 1178
         $action = Utils::createLambda($action, 'v,k', Functions::$blank);
1151 1179
 
1152
-        foreach ($this as $k => $v)
1153
-            $action($v, $k);
1180
+        foreach ($this as $k => $v) {
1181
+                    $action($v, $k);
1182
+        }
1154 1183
     }
1155 1184
 
1156 1185
     /**
Please login to merge, or discard this patch.
YaLinqo/EnumerablePagination.php 1 patch
Braces   +65 added lines, -46 removed lines patch added patch discarded remove patch
@@ -36,14 +36,16 @@  discard block
 block discarded – undo
36 36
         $it = $this->getIterator();
37 37
 
38 38
         if ($it instanceof ArrayAccess) {
39
-            if (!$it->offsetExists($key))
40
-                throw new UnexpectedValueException(Errors::NO_KEY);
39
+            if (!$it->offsetExists($key)) {
40
+                            throw new UnexpectedValueException(Errors::NO_KEY);
41
+            }
41 42
             return $it->offsetGet($key);
42 43
         }
43 44
 
44 45
         foreach ($it as $k => $v) {
45
-            if ($k === $key)
46
-                return $v;
46
+            if ($k === $key) {
47
+                            return $v;
48
+            }
47 49
         }
48 50
         throw new UnexpectedValueException(Errors::NO_KEY);
49 51
     }
@@ -63,12 +65,14 @@  discard block
 block discarded – undo
63 65
         /** @var $it Iterator|ArrayAccess */
64 66
         $it = $this->getIterator();
65 67
 
66
-        if ($it instanceof ArrayAccess)
67
-            return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
68
+        if ($it instanceof ArrayAccess) {
69
+                    return $it->offsetExists($key) ? $it->offsetGet($key) : $default;
70
+        }
68 71
 
69 72
         foreach ($it as $k => $v) {
70
-            if ($k === $key)
71
-                return $v;
73
+            if ($k === $key) {
74
+                            return $v;
75
+            }
72 76
         }
73 77
         return $default;
74 78
     }
@@ -91,8 +95,9 @@  discard block
 block discarded – undo
91 95
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
92 96
 
93 97
         foreach ($this as $k => $v) {
94
-            if ($predicate($v, $k))
95
-                return $v;
98
+            if ($predicate($v, $k)) {
99
+                            return $v;
100
+            }
96 101
         }
97 102
         throw new UnexpectedValueException(Errors::NO_MATCHES);
98 103
     }
@@ -114,8 +119,9 @@  discard block
 block discarded – undo
114 119
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
115 120
 
116 121
         foreach ($this as $k => $v) {
117
-            if ($predicate($v, $k))
118
-                return $v;
122
+            if ($predicate($v, $k)) {
123
+                            return $v;
124
+            }
119 125
         }
120 126
         return $default;
121 127
     }
@@ -137,8 +143,9 @@  discard block
 block discarded – undo
137 143
         $predicate = Utils::createLambda($predicate, 'v,k', Functions::$true);
138 144
 
139 145
         foreach ($this as $k => $v) {
140
-            if ($predicate($v, $k))
141
-                return $v;
146
+            if ($predicate($v, $k)) {
147
+                            return $v;
148
+            }
142 149
         }
143 150
         return $fallback();
144 151
     }
@@ -168,8 +175,9 @@  discard block
 block discarded – undo
168 175
                 $value = $v;
169 176
             }
170 177
         }
171
-        if (!$found)
172
-            throw new UnexpectedValueException(Errors::NO_MATCHES);
178
+        if (!$found) {
179
+                    throw new UnexpectedValueException(Errors::NO_MATCHES);
180
+        }
173 181
         return $value;
174 182
     }
175 183
 
@@ -245,8 +253,9 @@  discard block
 block discarded – undo
245 253
         $predicate = Utils::createLambda($predicate, 'v,k', false);
246 254
 
247 255
         list($found, $value) = $this->singleInternal($predicate);
248
-        if (!$found)
249
-            throw new UnexpectedValueException(Errors::NO_MATCHES);
256
+        if (!$found) {
257
+                    throw new UnexpectedValueException(Errors::NO_MATCHES);
258
+        }
250 259
         return $value;
251 260
     }
252 261
 
@@ -303,17 +312,18 @@  discard block
 block discarded – undo
303 312
         if ($predicate) {
304 313
             foreach ($this as $k => $v) {
305 314
                 if ($predicate($v, $k)) {
306
-                    if ($found)
307
-                        throw new UnexpectedValueException(Errors::MANY_MATCHES);
315
+                    if ($found) {
316
+                                            throw new UnexpectedValueException(Errors::MANY_MATCHES);
317
+                    }
308 318
                     $found = true;
309 319
                     $value = $v;
310 320
                 }
311 321
             }
312
-        }
313
-        else {
322
+        } else {
314 323
             foreach ($this as $v) {
315
-                if ($found)
316
-                    throw new UnexpectedValueException(Errors::MANY_ELEMENTS);
324
+                if ($found) {
325
+                                    throw new UnexpectedValueException(Errors::MANY_ELEMENTS);
326
+                }
317 327
                 $found = true;
318 328
                 $value = $v;
319 329
             }
@@ -335,11 +345,11 @@  discard block
 block discarded – undo
335 345
         if ($array !== null) {
336 346
             $keys = array_keys($array, $value, true);
337 347
             return empty($keys) ? null : $keys[0];
338
-        }
339
-        else {
348
+        } else {
340 349
             foreach ($this as $k => $v) {
341
-                if ($v === $value)
342
-                    return $k;
350
+                if ($v === $value) {
351
+                                    return $k;
352
+                }
343 353
             }
344 354
             return null;
345 355
         }
@@ -357,8 +367,9 @@  discard block
 block discarded – undo
357 367
     {
358 368
         $key = null;
359 369
         foreach ($this as $k => $v) {
360
-            if ($v === $value)
361
-                $key = $k;
370
+            if ($v === $value) {
371
+                            $key = $k;
372
+            }
362 373
         }
363 374
         return $key; // not -1
364 375
     }
@@ -376,8 +387,9 @@  discard block
 block discarded – undo
376 387
         $predicate = Utils::createLambda($predicate, 'v,k');
377 388
 
378 389
         foreach ($this as $k => $v) {
379
-            if ($predicate($v, $k))
380
-                return $k;
390
+            if ($predicate($v, $k)) {
391
+                            return $k;
392
+            }
381 393
         }
382 394
         return null; // not -1
383 395
     }
@@ -396,8 +408,9 @@  discard block
 block discarded – undo
396 408
 
397 409
         $key = null;
398 410
         foreach ($this as $k => $v) {
399
-            if ($predicate($v, $k))
400
-                $key = $k;
411
+            if ($predicate($v, $k)) {
412
+                            $key = $k;
413
+            }
401 414
         }
402 415
         return $key; // not -1
403 416
     }
@@ -416,8 +429,9 @@  discard block
 block discarded – undo
416 429
         return new self(function() use ($count) {
417 430
             $it = $this->getIterator();
418 431
             $it->rewind();
419
-            for ($i = 0; $i < $count && $it->valid(); ++$i)
420
-                $it->next();
432
+            for ($i = 0; $i < $count && $it->valid(); ++$i) {
433
+                            $it->next();
434
+            }
421 435
             while ($it->valid()) {
422 436
                 yield $it->key() => $it->current();
423 437
                 $it->next();
@@ -441,10 +455,12 @@  discard block
 block discarded – undo
441 455
         return new self(function() use ($predicate) {
442 456
             $yielding = false;
443 457
             foreach ($this as $k => $v) {
444
-                if (!$yielding && !$predicate($v, $k))
445
-                    $yielding = true;
446
-                if ($yielding)
447
-                    yield $k => $v;
458
+                if (!$yielding && !$predicate($v, $k)) {
459
+                                    $yielding = true;
460
+                }
461
+                if ($yielding) {
462
+                                    yield $k => $v;
463
+                }
448 464
             }
449 465
         });
450 466
     }
@@ -460,14 +476,16 @@  discard block
 block discarded – undo
460 476
      */
461 477
     public function take(int $count): Enumerable
462 478
     {
463
-        if ($count <= 0)
464
-            return new self(new EmptyIterator, false);
479
+        if ($count <= 0) {
480
+                    return new self(new EmptyIterator, false);
481
+        }
465 482
 
466 483
         return new self(function() use ($count) {
467 484
             foreach ($this as $k => $v) {
468 485
                 yield $k => $v;
469
-                if (--$count == 0)
470
-                    break;
486
+                if (--$count == 0) {
487
+                                    break;
488
+                }
471 489
             }
472 490
         });
473 491
     }
@@ -487,8 +505,9 @@  discard block
 block discarded – undo
487 505
 
488 506
         return new self(function() use ($predicate) {
489 507
             foreach ($this as $k => $v) {
490
-                if (!$predicate($v, $k))
491
-                    break;
508
+                if (!$predicate($v, $k)) {
509
+                                    break;
510
+                }
492 511
                 yield $k => $v;
493 512
             }
494 513
         });
Please login to merge, or discard this patch.
YaLinqo/OrderedEnumerable.php 1 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
-        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 {
134
+        } elseif ($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(array $orders, bool $canMultisort): Generator
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, array $orders, bool $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, array $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/EnumerableGeneration.php 1 patch
Braces   +37 added lines, -28 removed lines patch added patch discarded remove patch
@@ -40,8 +40,9 @@  discard block
 block discarded – undo
40 40
                     yield $v;
41 41
                     $isEmpty = false;
42 42
                 }
43
-                if ($isEmpty)
44
-                    throw new UnexpectedValueException(Errors::NO_ELEMENTS);
43
+                if ($isEmpty) {
44
+                                    throw new UnexpectedValueException(Errors::NO_ELEMENTS);
45
+                }
45 46
             }
46 47
         });
47 48
     }
@@ -77,14 +78,15 @@  discard block
 block discarded – undo
77 78
     public static function from($source): Enumerable
78 79
     {
79 80
         $it = null;
80
-        if ($source instanceof Enumerable)
81
-            return $source;
82
-        elseif (is_array($source))
83
-            $it = new ArrayIterator($source);
84
-        elseif ($source instanceof IteratorAggregate)
85
-            $it = $source->getIterator();
86
-        elseif ($source instanceof Traversable)
87
-            $it = $source;
81
+        if ($source instanceof Enumerable) {
82
+                    return $source;
83
+        } elseif (is_array($source)) {
84
+                    $it = new ArrayIterator($source);
85
+        } elseif ($source instanceof IteratorAggregate) {
86
+                    $it = $source->getIterator();
87
+        } elseif ($source instanceof Traversable) {
88
+                    $it = $source;
89
+        }
88 90
         if ($it !== null) {
89 91
             return new self($it, false);
90 92
         }
@@ -135,8 +137,9 @@  discard block
 block discarded – undo
135 137
     {
136 138
         return new self(function() use ($start, $step) {
137 139
             $value = $start - $step;
138
-            while (true)
139
-                yield $value += $step;
140
+            while (true) {
141
+                            yield $value += $step;
142
+            }
140 143
         });
141 144
     }
142 145
 
@@ -196,12 +199,14 @@  discard block
 block discarded – undo
196 199
      */
197 200
     public static function range(int $start, int $count, int $step = 1): Enumerable
198 201
     {
199
-        if ($count <= 0)
200
-            return self::emptyEnum();
202
+        if ($count <= 0) {
203
+                    return self::emptyEnum();
204
+        }
201 205
         return new self(function() use ($start, $count, $step) {
202 206
             $value = $start - $step;
203
-            while ($count-- > 0)
204
-                yield $value += $step;
207
+            while ($count-- > 0) {
208
+                            yield $value += $step;
209
+            }
205 210
         });
206 211
     }
207 212
 
@@ -235,16 +240,18 @@  discard block
 block discarded – undo
235 240
      */
236 241
     public static function rangeTo(int $start, int $end, $step = 1): Enumerable
237 242
     {
238
-        if ($step <= 0)
239
-            throw new InvalidArgumentException(Errors::STEP_NEGATIVE);
243
+        if ($step <= 0) {
244
+                    throw new InvalidArgumentException(Errors::STEP_NEGATIVE);
245
+        }
240 246
         return new self(function() use ($start, $end, $step) {
241 247
             if ($start <= $end) {
242
-                for ($i = $start; $i < $end; $i += $step)
243
-                    yield $i;
244
-            }
245
-            else {
246
-                for ($i = $start; $i > $end; $i -= $step)
247
-                    yield $i;
248
+                for ($i = $start; $i < $end; $i += $step) {
249
+                                    yield $i;
250
+                }
251
+            } else {
252
+                for ($i = $start; $i > $end; $i -= $step) {
253
+                                    yield $i;
254
+                }
248 255
             }
249 256
         });
250 257
     }
@@ -264,11 +271,13 @@  discard block
 block discarded – undo
264 271
      */
265 272
     public static function repeat($element, $count = null): Enumerable
266 273
     {
267
-        if ($count < 0)
268
-            throw new InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
274
+        if ($count < 0) {
275
+                    throw new InvalidArgumentException(Errors::COUNT_LESS_THAN_ZERO);
276
+        }
269 277
         return new self(function() use ($element, $count) {
270
-            for ($i = 0; $i < $count || $count === null; $i++)
271
-                yield $element;
278
+            for ($i = 0; $i < $count || $count === null; $i++) {
279
+                            yield $element;
280
+            }
272 281
         });
273 282
     }
274 283
 
Please login to merge, or discard this patch.