@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | * @return mixed |
| 101 | 101 | */ |
| 102 | 102 | function has() { |
| 103 | - $has = function($name, $object){ |
|
| 103 | + $has = function($name, $object) { |
|
| 104 | 104 | return contains($name, keys($object)); |
| 105 | 105 | }; |
| 106 | 106 | return apply(curry($has), func_get_args()); |
@@ -130,7 +130,7 @@ discard block |
||
| 130 | 130 | * @return mixed |
| 131 | 131 | */ |
| 132 | 132 | function get() { |
| 133 | - $get = function($name, $object){ |
|
| 133 | + $get = function($name, $object) { |
|
| 134 | 134 | $object = attributes($object); |
| 135 | 135 | return has($name, $object) |
| 136 | 136 | ? $object[$name] |
@@ -32,8 +32,9 @@ |
||
| 32 | 32 | */ |
| 33 | 33 | function attributes() { |
| 34 | 34 | $attrs = function($object) { |
| 35 | - if (is_object($object)) |
|
| 36 | - return get_object_vars($object); |
|
| 35 | + if (is_object($object)) { |
|
| 36 | + return get_object_vars($object); |
|
| 37 | + } |
|
| 37 | 38 | return $object; |
| 38 | 39 | }; |
| 39 | 40 | return apply(curry($attrs), func_get_args()); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | */ |
| 58 | 58 | function filter() { |
| 59 | - $filter = function($fn, $list){ |
|
| 59 | + $filter = function($fn, $list) { |
|
| 60 | 60 | return array_values(array_filter($list, $fn)); |
| 61 | 61 | }; |
| 62 | 62 | return apply(curry($filter), func_get_args()); |
@@ -78,7 +78,7 @@ discard block |
||
| 78 | 78 | * @return array |
| 79 | 79 | */ |
| 80 | 80 | function reduce() { |
| 81 | - $reduce = function($fn, $initial, $list){ |
|
| 81 | + $reduce = function($fn, $initial, $list) { |
|
| 82 | 82 | return array_reduce($list, $fn, $initial); |
| 83 | 83 | }; |
| 84 | 84 | return apply(curry($reduce), func_get_args()); |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | * @return array |
| 105 | 105 | */ |
| 106 | 106 | function each() { |
| 107 | - $each = function($fn, $list){ |
|
| 107 | + $each = function($fn, $list) { |
|
| 108 | 108 | foreach ($list as $item) { |
| 109 | 109 | apply($fn, [$item]); |
| 110 | 110 | } |
@@ -128,7 +128,7 @@ discard block |
||
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
| 130 | 130 | function head($list) { |
| 131 | - if(is_string($list)) |
|
| 131 | + if (is_string($list)) |
|
| 132 | 132 | return substr($list, 0, 1); |
| 133 | 133 | return (count($list) > 0) |
| 134 | 134 | ? $list[0] |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | * @return mixed |
| 151 | 151 | */ |
| 152 | 152 | function last($list) { |
| 153 | - if(is_string($list)) |
|
| 153 | + if (is_string($list)) |
|
| 154 | 154 | return substr($list, -1); |
| 155 | 155 | return (count($list) > 0) |
| 156 | 156 | ? $list[count($list) - 1] |
@@ -173,7 +173,7 @@ discard block |
||
| 173 | 173 | * @return array |
| 174 | 174 | */ |
| 175 | 175 | function init($list) { |
| 176 | - if(is_string($list)) |
|
| 176 | + if (is_string($list)) |
|
| 177 | 177 | return (strlen($list) > 1) |
| 178 | 178 | ? substr($list, 0, strlen($list) - 1) |
| 179 | 179 | : ''; |
@@ -198,7 +198,7 @@ discard block |
||
| 198 | 198 | * @return array |
| 199 | 199 | */ |
| 200 | 200 | function tail($list) { |
| 201 | - if(is_string($list)) |
|
| 201 | + if (is_string($list)) |
|
| 202 | 202 | return (strlen($list) > 1) |
| 203 | 203 | ? substr($list, 1) |
| 204 | 204 | : ''; |
@@ -393,7 +393,7 @@ discard block |
||
| 393 | 393 | * @return array |
| 394 | 394 | */ |
| 395 | 395 | function append() { |
| 396 | - $append = function ($item, $list) { |
|
| 396 | + $append = function($item, $list) { |
|
| 397 | 397 | return concat($list, [$item]); |
| 398 | 398 | }; |
| 399 | 399 | return apply(curry($append), func_get_args()); |
@@ -439,7 +439,7 @@ discard block |
||
| 439 | 439 | $take = function($count, $list) { |
| 440 | 440 | if ($count > $length || $count < -$length) |
| 441 | 441 | return []; |
| 442 | - if(is_string($list)) { |
|
| 442 | + if (is_string($list)) { |
|
| 443 | 443 | return ($count >= 0) |
| 444 | 444 | ? substr($list, 0, $count) |
| 445 | 445 | : substr($list, $count); |
@@ -695,9 +695,9 @@ discard block |
||
| 695 | 695 | */ |
| 696 | 696 | function slices() { |
| 697 | 697 | $slices = function($size, $list) { |
| 698 | - if(empty($list)) |
|
| 698 | + if (empty($list)) |
|
| 699 | 699 | return is_string($list) ? '' : []; |
| 700 | - if(length($list) <= $size) |
|
| 700 | + if (length($list) <= $size) |
|
| 701 | 701 | return [$list]; |
| 702 | 702 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 703 | 703 | }; |
@@ -770,7 +770,7 @@ discard block |
||
| 770 | 770 | function findLastIndex() { |
| 771 | 771 | $findLastIndex = function($predicate, $list) { |
| 772 | 772 | foreach (reverse(toPairs($list)) as $pair) { |
| 773 | - if($predicate($pair[1])) |
|
| 773 | + if ($predicate($pair[1])) |
|
| 774 | 774 | return $pair[0]; |
| 775 | 775 | } |
| 776 | 776 | return null; |
@@ -842,7 +842,7 @@ discard block |
||
| 842 | 842 | $indexOf = function($item, $list) { |
| 843 | 843 | if (is_string($list)) { |
| 844 | 844 | $index = strpos($list, $item); |
| 845 | - return (-1 == $index) |
|
| 845 | + return (- 1 == $index) |
|
| 846 | 846 | ? null |
| 847 | 847 | : $index; |
| 848 | 848 | } |
@@ -871,7 +871,7 @@ discard block |
||
| 871 | 871 | $lastIndexOf = function($item, $list) { |
| 872 | 872 | if (is_string($list)) { |
| 873 | 873 | $index = strrpos($list, $item); |
| 874 | - return (-1 == $index) |
|
| 874 | + return (- 1 == $index) |
|
| 875 | 875 | ? null |
| 876 | 876 | : $index; |
| 877 | 877 | } |
@@ -959,7 +959,7 @@ discard block |
||
| 959 | 959 | $groupBy = function($fn, $list) { |
| 960 | 960 | return reduce(function($result, $item) use($fn) { |
| 961 | 961 | $index = $fn($item); |
| 962 | - if (! isset($result[$index])) |
|
| 962 | + if (!isset($result[$index])) |
|
| 963 | 963 | $result[$index] = []; |
| 964 | 964 | $result[$index][] = $item; |
| 965 | 965 | return $result; |
@@ -128,8 +128,9 @@ discard block |
||
| 128 | 128 | * @return mixed |
| 129 | 129 | */ |
| 130 | 130 | function head($list) { |
| 131 | - if(is_string($list)) |
|
| 132 | - return substr($list, 0, 1); |
|
| 131 | + if(is_string($list)) { |
|
| 132 | + return substr($list, 0, 1); |
|
| 133 | + } |
|
| 133 | 134 | return (count($list) > 0) |
| 134 | 135 | ? $list[0] |
| 135 | 136 | : null; |
@@ -150,8 +151,9 @@ discard block |
||
| 150 | 151 | * @return mixed |
| 151 | 152 | */ |
| 152 | 153 | function last($list) { |
| 153 | - if(is_string($list)) |
|
| 154 | - return substr($list, -1); |
|
| 154 | + if(is_string($list)) { |
|
| 155 | + return substr($list, -1); |
|
| 156 | + } |
|
| 155 | 157 | return (count($list) > 0) |
| 156 | 158 | ? $list[count($list) - 1] |
| 157 | 159 | : null; |
@@ -173,10 +175,11 @@ discard block |
||
| 173 | 175 | * @return array |
| 174 | 176 | */ |
| 175 | 177 | function init($list) { |
| 176 | - if(is_string($list)) |
|
| 177 | - return (strlen($list) > 1) |
|
| 178 | + if(is_string($list)) { |
|
| 179 | + return (strlen($list) > 1) |
|
| 178 | 180 | ? substr($list, 0, strlen($list) - 1) |
| 179 | 181 | : ''; |
| 182 | + } |
|
| 180 | 183 | return (count($list) > 1) |
| 181 | 184 | ? array_slice($list, 0, count($list) - 1) |
| 182 | 185 | : []; |
@@ -198,10 +201,11 @@ discard block |
||
| 198 | 201 | * @return array |
| 199 | 202 | */ |
| 200 | 203 | function tail($list) { |
| 201 | - if(is_string($list)) |
|
| 202 | - return (strlen($list) > 1) |
|
| 204 | + if(is_string($list)) { |
|
| 205 | + return (strlen($list) > 1) |
|
| 203 | 206 | ? substr($list, 1) |
| 204 | 207 | : ''; |
| 208 | + } |
|
| 205 | 209 | return (count($list) > 1) |
| 206 | 210 | ? array_slice($list, 1) |
| 207 | 211 | : []; |
@@ -299,8 +303,9 @@ discard block |
||
| 299 | 303 | */ |
| 300 | 304 | function concat() { |
| 301 | 305 | $concat = function($list1, $list2) { |
| 302 | - if (is_string($list1)) |
|
| 303 | - return $list1 . $list2; |
|
| 306 | + if (is_string($list1)) { |
|
| 307 | + return $list1 . $list2; |
|
| 308 | + } |
|
| 304 | 309 | return array_merge($list1, $list2); |
| 305 | 310 | }; |
| 306 | 311 | return apply(curry($concat), func_get_args()); |
@@ -372,8 +377,9 @@ discard block |
||
| 372 | 377 | */ |
| 373 | 378 | function insertAll() { |
| 374 | 379 | $insertAll = function($position, $items, $list) { |
| 375 | - if ($position < 0) |
|
| 376 | - $position = length($list) - $position; |
|
| 380 | + if ($position < 0) { |
|
| 381 | + $position = length($list) - $position; |
|
| 382 | + } |
|
| 377 | 383 | return concatAll([take($position, $list), $items, remove($position, $list)]); |
| 378 | 384 | }; |
| 379 | 385 | return apply(curry($insertAll), func_get_args()); |
@@ -437,8 +443,9 @@ discard block |
||
| 437 | 443 | */ |
| 438 | 444 | function take() { |
| 439 | 445 | $take = function($count, $list) { |
| 440 | - if ($count > $length || $count < -$length) |
|
| 441 | - return []; |
|
| 446 | + if ($count > $length || $count < -$length) { |
|
| 447 | + return []; |
|
| 448 | + } |
|
| 442 | 449 | if(is_string($list)) { |
| 443 | 450 | return ($count >= 0) |
| 444 | 451 | ? substr($list, 0, $count) |
@@ -563,8 +570,9 @@ discard block |
||
| 563 | 570 | function remove() { |
| 564 | 571 | $remove = function($count, $list) { |
| 565 | 572 | $length = length($list); |
| 566 | - if ($count > $length || $count < -$length) |
|
| 567 | - return []; |
|
| 573 | + if ($count > $length || $count < -$length) { |
|
| 574 | + return []; |
|
| 575 | + } |
|
| 568 | 576 | return ($count > 0) |
| 569 | 577 | ? take($count - $length) |
| 570 | 578 | : take($count + $length); |
@@ -695,10 +703,12 @@ discard block |
||
| 695 | 703 | */ |
| 696 | 704 | function slices() { |
| 697 | 705 | $slices = function($size, $list) { |
| 698 | - if(empty($list)) |
|
| 699 | - return is_string($list) ? '' : []; |
|
| 700 | - if(length($list) <= $size) |
|
| 701 | - return [$list]; |
|
| 706 | + if(empty($list)) { |
|
| 707 | + return is_string($list) ? '' : []; |
|
| 708 | + } |
|
| 709 | + if(length($list) <= $size) { |
|
| 710 | + return [$list]; |
|
| 711 | + } |
|
| 702 | 712 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 703 | 713 | }; |
| 704 | 714 | return apply(curry($slices), func_get_args()); |
@@ -744,8 +754,9 @@ discard block |
||
| 744 | 754 | function findIndex() { |
| 745 | 755 | $findIndex = function($predicate, $list) { |
| 746 | 756 | foreach ($list as $key => $value) { |
| 747 | - if ($predicate($value)) |
|
| 748 | - return $key; |
|
| 757 | + if ($predicate($value)) { |
|
| 758 | + return $key; |
|
| 759 | + } |
|
| 749 | 760 | } |
| 750 | 761 | return null; |
| 751 | 762 | }; |
@@ -770,8 +781,9 @@ discard block |
||
| 770 | 781 | function findLastIndex() { |
| 771 | 782 | $findLastIndex = function($predicate, $list) { |
| 772 | 783 | foreach (reverse(toPairs($list)) as $pair) { |
| 773 | - if($predicate($pair[1])) |
|
| 774 | - return $pair[0]; |
|
| 784 | + if($predicate($pair[1])) { |
|
| 785 | + return $pair[0]; |
|
| 786 | + } |
|
| 775 | 787 | } |
| 776 | 788 | return null; |
| 777 | 789 | }; |
@@ -959,8 +971,9 @@ discard block |
||
| 959 | 971 | $groupBy = function($fn, $list) { |
| 960 | 972 | return reduce(function($result, $item) use($fn) { |
| 961 | 973 | $index = $fn($item); |
| 962 | - if (! isset($result[$index])) |
|
| 963 | - $result[$index] = []; |
|
| 974 | + if (! isset($result[$index])) { |
|
| 975 | + $result[$index] = []; |
|
| 976 | + } |
|
| 964 | 977 | $result[$index][] = $item; |
| 965 | 978 | return $result; |
| 966 | 979 | }, [], $list); |
@@ -13,7 +13,7 @@ discard block |
||
| 13 | 13 | * @return bool |
| 14 | 14 | */ |
| 15 | 15 | function and_() { |
| 16 | - return apply(curry(function($a, $b){ |
|
| 16 | + return apply(curry(function($a, $b) { |
|
| 17 | 17 | return $a && $b; |
| 18 | 18 | }), func_get_args()); |
| 19 | 19 | } |
@@ -27,7 +27,7 @@ discard block |
||
| 27 | 27 | * @return bool |
| 28 | 28 | */ |
| 29 | 29 | function or_() { |
| 30 | - return apply(curry(function($a, $b){ |
|
| 30 | + return apply(curry(function($a, $b) { |
|
| 31 | 31 | return $a || $b; |
| 32 | 32 | }), func_get_args()); |
| 33 | 33 | } |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | * @return bool |
| 56 | 56 | */ |
| 57 | 57 | function eq() { |
| 58 | - return apply(curry(function($a, $b){ |
|
| 58 | + return apply(curry(function($a, $b) { |
|
| 59 | 59 | return $a == $b; |
| 60 | 60 | }), func_get_args()); |
| 61 | 61 | } |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | * @return bool |
| 70 | 70 | */ |
| 71 | 71 | function eqq() { |
| 72 | - return apply(curry(function($a, $b){ |
|
| 72 | + return apply(curry(function($a, $b) { |
|
| 73 | 73 | return $a === $b; |
| 74 | 74 | }), func_get_args()); |
| 75 | 75 | } |
@@ -112,9 +112,7 @@ discard block |
||
| 112 | 112 | return $a == $b; |
| 113 | 113 | case 'List': |
| 114 | 114 | $length = length($a); |
| 115 | - return length($b) != $length ? false : |
|
| 116 | - 0 == $length ? true : |
|
| 117 | - equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 115 | + return length($b) != $length ? false : 0 == $length ? true : equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 118 | 116 | case 'Array': |
| 119 | 117 | case 'ArrayObject': |
| 120 | 118 | case 'Object': |
@@ -134,7 +132,7 @@ discard block |
||
| 134 | 132 | * @return bool |
| 135 | 133 | */ |
| 136 | 134 | function lt() { |
| 137 | - return apply(curry(function($a, $b){ |
|
| 135 | + return apply(curry(function($a, $b) { |
|
| 138 | 136 | return $a < $b; |
| 139 | 137 | }), func_get_args()); |
| 140 | 138 | } |
@@ -148,7 +146,7 @@ discard block |
||
| 148 | 146 | * @return bool |
| 149 | 147 | */ |
| 150 | 148 | function lte() { |
| 151 | - return apply(curry(function($a, $b){ |
|
| 149 | + return apply(curry(function($a, $b) { |
|
| 152 | 150 | return $a <= $b; |
| 153 | 151 | }), func_get_args()); |
| 154 | 152 | } |
@@ -162,7 +160,7 @@ discard block |
||
| 162 | 160 | * @return bool |
| 163 | 161 | */ |
| 164 | 162 | function gt() { |
| 165 | - return apply(curry(function($a, $b){ |
|
| 163 | + return apply(curry(function($a, $b) { |
|
| 166 | 164 | return $a > $b; |
| 167 | 165 | }), func_get_args()); |
| 168 | 166 | } |
@@ -176,7 +174,7 @@ discard block |
||
| 176 | 174 | * @return bool |
| 177 | 175 | */ |
| 178 | 176 | function gte() { |
| 179 | - return apply(curry(function($a, $b){ |
|
| 177 | + return apply(curry(function($a, $b) { |
|
| 180 | 178 | return $a >= $b; |
| 181 | 179 | }), func_get_args()); |
| 182 | 180 | } |
@@ -97,8 +97,9 @@ |
||
| 97 | 97 | function equals() { |
| 98 | 98 | $equals = function($a, $b) { |
| 99 | 99 | $type = type($a); |
| 100 | - if ($type != type($b)) |
|
| 101 | - return false; |
|
| 100 | + if ($type != type($b)) { |
|
| 101 | + return false; |
|
| 102 | + } |
|
| 102 | 103 | switch ($type) { |
| 103 | 104 | case 'Null': |
| 104 | 105 | case 'Boolean': |