@@ -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 |
@@ -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) { |
@@ -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() { |
@@ -174,7 +172,6 @@ discard block |
||
174 | 172 | * ``` |
175 | 173 | * |
176 | 174 | * @signature (((a, b, ...) -> o), (o -> p), ..., (y -> z)) -> ((a, b, ...) -> z) |
177 | - * @param callable $fns... |
|
178 | 175 | * @return callable |
179 | 176 | */ |
180 | 177 | function pipe() { |
@@ -218,7 +215,6 @@ discard block |
||
218 | 215 | * ``` |
219 | 216 | * |
220 | 217 | * @signature a -> (* -> a) |
221 | - * @param mixed $value |
|
222 | 218 | * @return callable |
223 | 219 | */ |
224 | 220 | function give() { |
@@ -245,8 +241,7 @@ discard block |
||
245 | 241 | * ``` |
246 | 242 | * |
247 | 243 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
248 | - * @param callable $predicates... |
|
249 | - * @return callable |
|
244 | + * @return \Closure |
|
250 | 245 | */ |
251 | 246 | function all() { |
252 | 247 | $predicates = func_get_args(); |
@@ -276,8 +271,7 @@ discard block |
||
276 | 271 | * ``` |
277 | 272 | * |
278 | 273 | * @signature ((a -> Boolean), ..., (a -> Boolean)) -> (a -> Boolean) |
279 | - * @param callable $predicates... |
|
280 | - * @return callable |
|
274 | + * @return \Closure |
|
281 | 275 | */ |
282 | 276 | function any() { |
283 | 277 | $predicates = func_get_args(); |