@@ -2,8 +2,7 @@ |
||
| 2 | 2 | |
| 3 | 3 | function numberOfArgs($fn) { |
| 4 | 4 | $reflector = is_array($fn) ? |
| 5 | - new ReflectionMethod($fn[0], $fn[1]) : |
|
| 6 | - new ReflectionFunction($fn); |
|
| 5 | + new ReflectionMethod($fn[0], $fn[1]) : new ReflectionFunction($fn); |
|
| 7 | 6 | return $reflector->getNumberOfParameters(); |
| 8 | 7 | } |
| 9 | 8 | |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | * @param callable $fn |
| 81 | 81 | * @param int $argsCount |
| 82 | 82 | * @param array $boundArgs |
| 83 | - * @return callable |
|
| 83 | + * @return \Closure |
|
| 84 | 84 | */ |
| 85 | 85 | function _curried_function($fn, $argsCount, $boundArgs = []) { |
| 86 | 86 | return function() use($fn, $argsCount, $boundArgs) { |
@@ -152,8 +152,6 @@ discard block |
||
| 152 | 152 | * ``` |
| 153 | 153 | * |
| 154 | 154 | * @signature (*... -> a) -> [*] -> a |
| 155 | - * @param callable $fn |
|
| 156 | - * @param array $args |
|
| 157 | 155 | * @return mixed |
| 158 | 156 | */ |
| 159 | 157 | function apply() { |
@@ -28,8 +28,7 @@ discard block |
||
| 28 | 28 | */ |
| 29 | 29 | function _number_of_args($fn) { |
| 30 | 30 | $reflector = is_array($fn) ? |
| 31 | - new \ReflectionMethod($fn[0], $fn[1]) : |
|
| 32 | - new \ReflectionFunction($fn); |
|
| 31 | + new \ReflectionMethod($fn[0], $fn[1]) : new \ReflectionFunction($fn); |
|
| 33 | 32 | return $reflector->getNumberOfRequiredParameters(); |
| 34 | 33 | } |
| 35 | 34 | |
@@ -59,7 +58,7 @@ discard block |
||
| 59 | 58 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 60 | 59 | $currentBoundArgsCount = count($currentBoundArgs); |
| 61 | 60 | $placeholderPosition = 0; |
| 62 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 61 | + while ($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 63 | 62 | $placeholderPosition ++; |
| 64 | 63 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 65 | 64 | $currentBoundArgs[] = $arg; |
@@ -179,9 +178,9 @@ discard block |
||
| 179 | 178 | */ |
| 180 | 179 | function pipe() { |
| 181 | 180 | $fns = func_get_args(); |
| 182 | - if(count($fns) < 1) |
|
| 181 | + if (count($fns) < 1) |
|
| 183 | 182 | throw new InvalidArgument("pipe() requires at least one argument"); |
| 184 | - return curry(function () use ($fns) { |
|
| 183 | + return curry(function() use ($fns) { |
|
| 185 | 184 | $result = _apply(array_shift($fns), func_get_args()); |
| 186 | 185 | foreach ($fns as $fn) { |
| 187 | 186 | $result = $fn($result); |
@@ -59,8 +59,9 @@ discard block |
||
| 59 | 59 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 60 | 60 | $currentBoundArgsCount = count($currentBoundArgs); |
| 61 | 61 | $placeholderPosition = 0; |
| 62 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 63 | - $placeholderPosition ++; |
|
| 62 | + while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) { |
|
| 63 | + $placeholderPosition ++; |
|
| 64 | + } |
|
| 64 | 65 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 65 | 66 | $currentBoundArgs[] = $arg; |
| 66 | 67 | } else { // There is a placeholder and number of bound args > $fnArgsCount |
@@ -87,8 +88,9 @@ discard block |
||
| 87 | 88 | $boundArgs = _merge_args($argsCount, $boundArgs, func_get_args()); |
| 88 | 89 | $numberOfPlaceholders = count(array_filter($boundArgs, _f('_is_placeholder'))); |
| 89 | 90 | $numberOfGivenArgs = count($boundArgs) - $numberOfPlaceholders; |
| 90 | - if ($numberOfGivenArgs >= $argsCount) |
|
| 91 | - return call_user_func_array($fn, $boundArgs); |
|
| 91 | + if ($numberOfGivenArgs >= $argsCount) { |
|
| 92 | + return call_user_func_array($fn, $boundArgs); |
|
| 93 | + } |
|
| 92 | 94 | return _curried_function($fn, $argsCount, $boundArgs); |
| 93 | 95 | }; |
| 94 | 96 | } |
@@ -179,8 +181,9 @@ discard block |
||
| 179 | 181 | */ |
| 180 | 182 | function pipe() { |
| 181 | 183 | $fns = func_get_args(); |
| 182 | - if(count($fns) < 1) |
|
| 183 | - throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 184 | + if(count($fns) < 1) { |
|
| 185 | + throw new InvalidArgument("pipe() requires at least one argument"); |
|
| 186 | + } |
|
| 184 | 187 | return curry(function () use ($fns) { |
| 185 | 188 | $result = _apply(array_shift($fns), func_get_args()); |
| 186 | 189 | foreach ($fns as $fn) { |