@@ -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': |
@@ -22,7 +22,7 @@ discard block |
||
| 22 | 22 | */ |
| 23 | 23 | function and_() { |
| 24 | 24 | static $and = false; |
| 25 | - $and = $and ?: curry(function($a, $b){ |
|
| 25 | + $and = $and ?: curry(function($a, $b) { |
|
| 26 | 26 | return $a && $b; |
| 27 | 27 | }); |
| 28 | 28 | return _apply($and, func_get_args()); |
@@ -45,7 +45,7 @@ discard block |
||
| 45 | 45 | */ |
| 46 | 46 | function or_() { |
| 47 | 47 | static $or = false; |
| 48 | - $or = $or ?: curry(function($a, $b){ |
|
| 48 | + $or = $or ?: curry(function($a, $b) { |
|
| 49 | 49 | return $a || $b; |
| 50 | 50 | }); |
| 51 | 51 | return _apply($or, func_get_args()); |
@@ -85,7 +85,7 @@ discard block |
||
| 85 | 85 | * @return bool |
| 86 | 86 | */ |
| 87 | 87 | function eq() { |
| 88 | - $eq = curry(function($a, $b){ |
|
| 88 | + $eq = curry(function($a, $b) { |
|
| 89 | 89 | return $a == $b; |
| 90 | 90 | }); |
| 91 | 91 | return _apply($eq, func_get_args()); |
@@ -106,7 +106,7 @@ discard block |
||
| 106 | 106 | */ |
| 107 | 107 | function notEq() { |
| 108 | 108 | static $notEq = false; |
| 109 | - $notEq = $notEq ?: curry(function($a, $b){ |
|
| 109 | + $notEq = $notEq ?: curry(function($a, $b) { |
|
| 110 | 110 | return $a != $b; |
| 111 | 111 | }); |
| 112 | 112 | return _apply($notEq, func_get_args()); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | function eqq() { |
| 128 | 128 | static $eqq = false; |
| 129 | - $eqq = $eqq ?: curry(function($a, $b){ |
|
| 129 | + $eqq = $eqq ?: curry(function($a, $b) { |
|
| 130 | 130 | return $a === $b; |
| 131 | 131 | }); |
| 132 | 132 | return _apply($eqq, func_get_args()); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function notEqq() { |
| 149 | 149 | static $notEqq = false; |
| 150 | - $notEqq = $notEqq ?: curry(function($a, $b){ |
|
| 150 | + $notEqq = $notEqq ?: curry(function($a, $b) { |
|
| 151 | 151 | return $a !== $b; |
| 152 | 152 | }); |
| 153 | 153 | return _apply($notEqq, func_get_args()); |
@@ -196,9 +196,7 @@ discard block |
||
| 196 | 196 | return $a == $b; |
| 197 | 197 | case 'List': |
| 198 | 198 | $length = length($a); |
| 199 | - return length($b) != $length ? false : |
|
| 200 | - 0 == $length ? true : |
|
| 201 | - equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 199 | + return length($b) != $length ? false : 0 == $length ? true : equals(head($a), head($b)) && equals(tail($a), tail($b)); |
|
| 202 | 200 | case 'Array': |
| 203 | 201 | case 'ArrayObject': |
| 204 | 202 | case 'Object': |
@@ -252,7 +250,7 @@ discard block |
||
| 252 | 250 | */ |
| 253 | 251 | function lt() { |
| 254 | 252 | static $lt = false; |
| 255 | - $lt = $lt ?: curry(function($a, $b){ |
|
| 253 | + $lt = $lt ?: curry(function($a, $b) { |
|
| 256 | 254 | return $a < $b; |
| 257 | 255 | }); |
| 258 | 256 | return _apply($lt, func_get_args()); |
@@ -274,7 +272,7 @@ discard block |
||
| 274 | 272 | */ |
| 275 | 273 | function lte() { |
| 276 | 274 | static $lte = false; |
| 277 | - $lte = $lte ?: curry(function($a, $b){ |
|
| 275 | + $lte = $lte ?: curry(function($a, $b) { |
|
| 278 | 276 | return $a <= $b; |
| 279 | 277 | }); |
| 280 | 278 | return _apply($lte, func_get_args()); |
@@ -296,7 +294,7 @@ discard block |
||
| 296 | 294 | */ |
| 297 | 295 | function gt() { |
| 298 | 296 | static $gt = false; |
| 299 | - $gt = $gt ?: curry(function($a, $b){ |
|
| 297 | + $gt = $gt ?: curry(function($a, $b) { |
|
| 300 | 298 | return $a > $b; |
| 301 | 299 | }); |
| 302 | 300 | return _apply($gt, func_get_args()); |
@@ -318,7 +316,7 @@ discard block |
||
| 318 | 316 | */ |
| 319 | 317 | function gte() { |
| 320 | 318 | static $gte = false; |
| 321 | - $gte = $gte ?: curry(function($a, $b){ |
|
| 319 | + $gte = $gte ?: curry(function($a, $b) { |
|
| 322 | 320 | return $a >= $b; |
| 323 | 321 | }); |
| 324 | 322 | return _apply($gte, func_get_args()); |
@@ -72,8 +72,9 @@ discard block |
||
| 72 | 72 | */ |
| 73 | 73 | function attributes() { |
| 74 | 74 | $attrs = function($object) { |
| 75 | - if (is_object($object)) |
|
| 76 | - return get_object_vars($object); |
|
| 75 | + if (is_object($object)) { |
|
| 76 | + return get_object_vars($object); |
|
| 77 | + } |
|
| 77 | 78 | return $object; |
| 78 | 79 | }; |
| 79 | 80 | return apply(curry($attrs), func_get_args()); |
@@ -208,8 +209,9 @@ discard block |
||
| 208 | 209 | function getPath() { |
| 209 | 210 | $getPath = function($path, $object){ |
| 210 | 211 | return reduce(function($result, $name) { |
| 211 | - if ($result !== null) |
|
| 212 | - $result = get($name, $result); |
|
| 212 | + if ($result !== null) { |
|
| 213 | + $result = get($name, $result); |
|
| 214 | + } |
|
| 213 | 215 | return $result; |
| 214 | 216 | }, $object, $path); |
| 215 | 217 | }; |
@@ -237,10 +239,11 @@ discard block |
||
| 237 | 239 | function set() { |
| 238 | 240 | $set = function($name, $value, $object) { |
| 239 | 241 | $object = clone_($object); |
| 240 | - if (is_object($object)) |
|
| 241 | - $object->{$name} = $value; |
|
| 242 | - else |
|
| 243 | - $object[$name] = $value; |
|
| 242 | + if (is_object($object)) { |
|
| 243 | + $object->{$name} = $value; |
|
| 244 | + } else { |
|
| 245 | + $object[$name] = $value; |
|
| 246 | + } |
|
| 244 | 247 | return $object; |
| 245 | 248 | }; |
| 246 | 249 | return apply(curry($set), func_get_args()); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | function has() { |
| 170 | 170 | static $has = false; |
| 171 | - $has = $has ?: curry(function($name, $object){ |
|
| 171 | + $has = $has ?: curry(function($name, $object) { |
|
| 172 | 172 | return contains($name, keys($object)); |
| 173 | 173 | }); |
| 174 | 174 | return _apply($has, func_get_args()); |
@@ -201,7 +201,7 @@ discard block |
||
| 201 | 201 | */ |
| 202 | 202 | function get() { |
| 203 | 203 | static $get = false; |
| 204 | - $get = $get ?: curry(function($name, $object){ |
|
| 204 | + $get = $get ?: curry(function($name, $object) { |
|
| 205 | 205 | $object = attributes($object); |
| 206 | 206 | return has($name, $object) |
| 207 | 207 | ? $object[$name] |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | */ |
| 234 | 234 | function getPath() { |
| 235 | 235 | static $getPath = false; |
| 236 | - $getPath = $getPath ?: curry(function($path, $object){ |
|
| 236 | + $getPath = $getPath ?: curry(function($path, $object) { |
|
| 237 | 237 | return reduce(function($result, $name) { |
| 238 | 238 | if ($result !== null) |
| 239 | 239 | $result = get($name, $result); |
@@ -82,7 +82,7 @@ discard block |
||
| 82 | 82 | * @param mixed $something |
| 83 | 83 | * @return string |
| 84 | 84 | */ |
| 85 | -function toString () { |
|
| 85 | +function toString() { |
|
| 86 | 86 | $toString = function($something) { |
| 87 | 87 | switch (type($something)) { |
| 88 | 88 | case 'String': |
@@ -105,11 +105,11 @@ discard block |
||
| 105 | 105 | return $something->__toString(); |
| 106 | 106 | case 'Object': |
| 107 | 107 | case 'Array': |
| 108 | - return '{' . join(', ', map(function($pair){ |
|
| 109 | - return $pair[0].': '. toString($pair[1]); |
|
| 108 | + return '{' . join(', ', map(function($pair) { |
|
| 109 | + return $pair[0] . ': ' . toString($pair[1]); |
|
| 110 | 110 | }, toPairs($something))) . '}'; |
| 111 | 111 | default: |
| 112 | - return '['.type($something).']'; |
|
| 112 | + return '[' . type($something) . ']'; |
|
| 113 | 113 | } |
| 114 | 114 | }; |
| 115 | 115 | return apply(curry($toString), func_get_args()); |
@@ -33,9 +33,15 @@ discard block |
||
| 33 | 33 | function type() { |
| 34 | 34 | static $type = false; |
| 35 | 35 | $type = $type ?: curry(function($data) { |
| 36 | - if ($data instanceof Error) return 'Error'; |
|
| 37 | - if ($data instanceof Stream) return 'Stream'; |
|
| 38 | - if (is_callable($data)) return 'Function'; |
|
| 36 | + if ($data instanceof Error) { |
|
| 37 | + return 'Error'; |
|
| 38 | + } |
|
| 39 | + if ($data instanceof Stream) { |
|
| 40 | + return 'Stream'; |
|
| 41 | + } |
|
| 42 | + if (is_callable($data)) { |
|
| 43 | + return 'Function'; |
|
| 44 | + } |
|
| 39 | 45 | switch (gettype($data)) { |
| 40 | 46 | case 'boolean': |
| 41 | 47 | return 'Boolean'; |
@@ -49,8 +55,9 @@ discard block |
||
| 49 | 55 | case 'resource': |
| 50 | 56 | return 'Resource'; |
| 51 | 57 | case 'array': |
| 52 | - if (allSatisfies('is_numeric', keys($data))) |
|
| 53 | - return 'List'; |
|
| 58 | + if (allSatisfies('is_numeric', keys($data))) { |
|
| 59 | + return 'List'; |
|
| 60 | + } |
|
| 54 | 61 | return 'Array'; |
| 55 | 62 | case 'object': |
| 56 | 63 | return 'Object'; |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | * @return array |
| 117 | 117 | */ |
| 118 | 118 | function get_modules() { |
| 119 | - $composer = json_decode(file_get_contents(__DIR__.'/composer.json')); |
|
| 119 | + $composer = json_decode(file_get_contents(__DIR__ . '/composer.json')); |
|
| 120 | 120 | return $composer->autoload->files; |
| 121 | 121 | } |
| 122 | 122 | |
@@ -147,10 +147,10 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function write_module($module) { |
| 149 | 149 | if ($module->docs) { |
| 150 | - $docsDir = dirname($module->docsPath); |
|
| 150 | + $docsDir = dirname($module->docsPath); |
|
| 151 | 151 | if (!is_dir($docsDir)) |
| 152 | 152 | mkdir($docsDir, 0777, true); |
| 153 | - file_put_contents($module->docsPath, $module->docs); |
|
| 153 | + file_put_contents($module->docsPath, $module->docs); |
|
| 154 | 154 | } |
| 155 | 155 | if ($module->tests) { |
| 156 | 156 | $testsDir = dirname($module->testsPath); |
@@ -179,7 +179,7 @@ discard block |
||
| 179 | 179 | 'fill_docs_path', |
| 180 | 180 | 'fill_tests_path', |
| 181 | 181 | 'fill_blocks' |
| 182 | - ]), [(object)['path' => $path]]); |
|
| 182 | + ]), [(object) ['path' => $path]]); |
|
| 183 | 183 | } |
| 184 | 184 | |
| 185 | 185 | /** |
@@ -233,8 +233,8 @@ discard block |
||
| 233 | 233 | function fill_blocks($module) { |
| 234 | 234 | $module->blocks = apply(pipe( |
| 235 | 235 | prepend('dox -r < '), // "dox -r < src/...php" |
| 236 | - 'shell_exec', // "[{...}, ...]" |
|
| 237 | - 'json_decode', // [DoxBlock] |
|
| 236 | + 'shell_exec', // "[{...}, ...]" |
|
| 237 | + 'json_decode', // [DoxBlock] |
|
| 238 | 238 | map(_f('make_block')) |
| 239 | 239 | // sort() |
| 240 | 240 | ), [$module->path]); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | if (has('class', $tags)) $type = 'class'; |
| 257 | 257 | if (has('method', $tags)) $type = 'method'; |
| 258 | 258 | |
| 259 | - $params = map(function($tag){ |
|
| 259 | + $params = map(function($tag) { |
|
| 260 | 260 | $parts = split(' ', get('value', $tag)); |
| 261 | 261 | return [ |
| 262 | 262 | 'type' => $parts[0], |
@@ -292,7 +292,7 @@ discard block |
||
| 292 | 292 | */ |
| 293 | 293 | function tags_of($doxBlock) { |
| 294 | 294 | if ($doxBlock->tags) |
| 295 | - return map(function($tag){ |
|
| 295 | + return map(function($tag) { |
|
| 296 | 296 | return (object) [ |
| 297 | 297 | 'name' => $tag->type, |
| 298 | 298 | 'value' => $tag->string |
@@ -341,7 +341,7 @@ discard block |
||
| 341 | 341 | * @return object |
| 342 | 342 | */ |
| 343 | 343 | function generate_docs_sommaire($module) { |
| 344 | - $blocks = filter ( |
|
| 344 | + $blocks = filter( |
|
| 345 | 345 | satisfiesAll(['ignore' => not(), 'internal' => not(), 'type' => equals('function')]), |
| 346 | 346 | $module->blocks |
| 347 | 347 | ); |
@@ -371,7 +371,7 @@ discard block |
||
| 371 | 371 | * @return object |
| 372 | 372 | */ |
| 373 | 373 | function generate_docs_contents($module) { |
| 374 | - $blocks = filter ( |
|
| 374 | + $blocks = filter( |
|
| 375 | 375 | satisfiesAll(['ignore' => not(), 'internal' => not()]), |
| 376 | 376 | $module->blocks |
| 377 | 377 | ); |
@@ -429,7 +429,7 @@ discard block |
||
| 429 | 429 | $additionalNamespace = replace("/", "\\", remove(6, dirname($module->testsPath))); |
| 430 | 430 | if ($additionalNamespace) |
| 431 | 431 | $namespace .= "\\" . $additionalNamespace; |
| 432 | - $name = remove(-4, last(split("/", $module->testsPath))); |
|
| 432 | + $name = remove(- 4, last(split("/", $module->testsPath))); |
|
| 433 | 433 | $module->tests .= "<?php namespace {$namespace};\n\nuse Tarsana\Functional as F;\n\nclass {$name} extends \Tarsana\UnitTests\Functional\UnitTest {\n"; |
| 434 | 434 | return $module; |
| 435 | 435 | } |
@@ -442,7 +442,7 @@ discard block |
||
| 442 | 442 | * @return object |
| 443 | 443 | */ |
| 444 | 444 | function generate_tests_contents($module) { |
| 445 | - $blocks = filter ( |
|
| 445 | + $blocks = filter( |
|
| 446 | 446 | satisfiesAll(['ignore' => not()]), |
| 447 | 447 | $module->blocks |
| 448 | 448 | ); |
@@ -499,7 +499,7 @@ discard block |
||
| 499 | 499 | if (!contains('```php', $description)) |
| 500 | 500 | return ''; |
| 501 | 501 | $code = remove(7 + indexOf('```php', $description), $description); |
| 502 | - return remove(-4, trim($code)); |
|
| 502 | + return remove(- 4, trim($code)); |
|
| 503 | 503 | } |
| 504 | 504 | |
| 505 | 505 | /** |
@@ -552,7 +552,7 @@ discard block |
||
| 552 | 552 | * @return array |
| 553 | 553 | */ |
| 554 | 554 | function generate_stream_operations($module) { |
| 555 | - $blocks = filter ( |
|
| 555 | + $blocks = filter( |
|
| 556 | 556 | satisfiesAll(['ignore' => equals(false), 'stream' => equals(true)]), |
| 557 | 557 | $module->blocks |
| 558 | 558 | ); |
@@ -621,7 +621,7 @@ discard block |
||
| 621 | 621 | * @return array |
| 622 | 622 | */ |
| 623 | 623 | function generate_stream_methods($module) { |
| 624 | - $blocks = filter ( |
|
| 624 | + $blocks = filter( |
|
| 625 | 625 | satisfiesAll(['ignore' => equals(false), 'stream' => equals(true)]), |
| 626 | 626 | $module->blocks |
| 627 | 627 | ); |
@@ -148,14 +148,16 @@ discard block |
||
| 148 | 148 | function write_module($module) { |
| 149 | 149 | if ($module->docs) { |
| 150 | 150 | $docsDir = dirname($module->docsPath); |
| 151 | - if (!is_dir($docsDir)) |
|
| 152 | - mkdir($docsDir, 0777, true); |
|
| 151 | + if (!is_dir($docsDir)) { |
|
| 152 | + mkdir($docsDir, 0777, true); |
|
| 153 | + } |
|
| 153 | 154 | file_put_contents($module->docsPath, $module->docs); |
| 154 | 155 | } |
| 155 | 156 | if ($module->tests) { |
| 156 | 157 | $testsDir = dirname($module->testsPath); |
| 157 | - if (!is_dir($testsDir)) |
|
| 158 | - mkdir($testsDir, 0777, true); |
|
| 158 | + if (!is_dir($testsDir)) { |
|
| 159 | + mkdir($testsDir, 0777, true); |
|
| 160 | + } |
|
| 159 | 161 | file_put_contents($module->testsPath, $module->tests); |
| 160 | 162 | } |
| 161 | 163 | if ($module->streamOperations) { |
@@ -252,9 +254,15 @@ discard block |
||
| 252 | 254 | $tags = groupBy(get('name'), tags_of($doxBlock)); |
| 253 | 255 | |
| 254 | 256 | $type = 'function'; |
| 255 | - if (has('file', $tags)) $type = 'file'; |
|
| 256 | - if (has('class', $tags)) $type = 'class'; |
|
| 257 | - if (has('method', $tags)) $type = 'method'; |
|
| 257 | + if (has('file', $tags)) { |
|
| 258 | + $type = 'file'; |
|
| 259 | + } |
|
| 260 | + if (has('class', $tags)) { |
|
| 261 | + $type = 'class'; |
|
| 262 | + } |
|
| 263 | + if (has('method', $tags)) { |
|
| 264 | + $type = 'method'; |
|
| 265 | + } |
|
| 258 | 266 | |
| 259 | 267 | $params = map(function($tag){ |
| 260 | 268 | $parts = split(' ', get('value', $tag)); |
@@ -266,8 +274,9 @@ discard block |
||
| 266 | 274 | |
| 267 | 275 | $return = getPath(['return', 0, 'value'], $tags); |
| 268 | 276 | $signatures = get('signature', $tags); |
| 269 | - if ($signatures) |
|
| 270 | - $signatures = map(get('value'), $signatures); |
|
| 277 | + if ($signatures) { |
|
| 278 | + $signatures = map(get('value'), $signatures); |
|
| 279 | + } |
|
| 271 | 280 | return (object) [ |
| 272 | 281 | 'type' => $type, |
| 273 | 282 | 'name' => getPath(['ctx', 'name'], $doxBlock), |
@@ -291,12 +300,13 @@ discard block |
||
| 291 | 300 | * @return array |
| 292 | 301 | */ |
| 293 | 302 | function tags_of($doxBlock) { |
| 294 | - if ($doxBlock->tags) |
|
| 295 | - return map(function($tag){ |
|
| 303 | + if ($doxBlock->tags) { |
|
| 304 | + return map(function($tag){ |
|
| 296 | 305 | return (object) [ |
| 297 | 306 | 'name' => $tag->type, |
| 298 | 307 | 'value' => $tag->string |
| 299 | 308 | ]; |
| 309 | + } |
|
| 300 | 310 | }, $doxBlock->tags); |
| 301 | 311 | return []; |
| 302 | 312 | } |
@@ -310,8 +320,9 @@ discard block |
||
| 310 | 320 | */ |
| 311 | 321 | function generate_docs($module) { |
| 312 | 322 | $module->docs = ''; |
| 313 | - if (startsWith('_', $module->name)) |
|
| 314 | - return $module; |
|
| 323 | + if (startsWith('_', $module->name)) { |
|
| 324 | + return $module; |
|
| 325 | + } |
|
| 315 | 326 | return apply(process_of([ |
| 316 | 327 | 'generate_docs_header', |
| 317 | 328 | 'generate_docs_sommaire', |
@@ -388,15 +399,17 @@ discard block |
||
| 388 | 399 | * @return string |
| 389 | 400 | */ |
| 390 | 401 | function generate_docs_contents_item($block) { |
| 391 | - if ($block->type != 'function') |
|
| 392 | - return ''; |
|
| 402 | + if ($block->type != 'function') { |
|
| 403 | + return ''; |
|
| 404 | + } |
|
| 393 | 405 | $params = join(', ', map(pipe(values(), join(' ')), get('params', $block))); |
| 394 | 406 | $return = get('return', $block); |
| 395 | 407 | $prototype = "```php\n{$block->name}({$params}) : {$return}\n```\n\n"; |
| 396 | 408 | $signature = ''; |
| 397 | 409 | $blockSignature = join("\n", $block->signatures); |
| 398 | - if ($blockSignature) |
|
| 399 | - $signature = "```\n{$blockSignature}\n```\n\n"; |
|
| 410 | + if ($blockSignature) { |
|
| 411 | + $signature = "```\n{$blockSignature}\n```\n\n"; |
|
| 412 | + } |
|
| 400 | 413 | return "# {$block->name}\n\n{$prototype}{$signature}{$block->description}\n\n"; |
| 401 | 414 | } |
| 402 | 415 | |
@@ -427,8 +440,9 @@ discard block |
||
| 427 | 440 | function generate_tests_header($module) { |
| 428 | 441 | $namespace = "Tarsana\UnitTests\Functional"; |
| 429 | 442 | $additionalNamespace = replace("/", "\\", remove(6, dirname($module->testsPath))); |
| 430 | - if ($additionalNamespace) |
|
| 431 | - $namespace .= "\\" . $additionalNamespace; |
|
| 443 | + if ($additionalNamespace) { |
|
| 444 | + $namespace .= "\\" . $additionalNamespace; |
|
| 445 | + } |
|
| 432 | 446 | $name = remove(-4, last(split("/", $module->testsPath))); |
| 433 | 447 | $module->tests .= "<?php namespace {$namespace};\n\nuse Tarsana\Functional as F;\n\nclass {$name} extends \Tarsana\UnitTests\Functional\UnitTest {\n"; |
| 434 | 448 | return $module; |
@@ -449,10 +463,11 @@ discard block |
||
| 449 | 463 | $contents = join("\n", map(function($block) use($module) { |
| 450 | 464 | return generate_tests_contents_item($block, $module); |
| 451 | 465 | }, $blocks)); |
| 452 | - if (trim($contents) != '') |
|
| 453 | - $module->tests .= $contents; |
|
| 454 | - else |
|
| 455 | - $module->tests = ''; |
|
| 466 | + if (trim($contents) != '') { |
|
| 467 | + $module->tests .= $contents; |
|
| 468 | + } else { |
|
| 469 | + $module->tests = ''; |
|
| 470 | + } |
|
| 456 | 471 | return $module; |
| 457 | 472 | } |
| 458 | 473 | |
@@ -465,8 +480,9 @@ discard block |
||
| 465 | 480 | * @return string |
| 466 | 481 | */ |
| 467 | 482 | function generate_tests_contents_item($block, $module) { |
| 468 | - if ($block->type != 'function') |
|
| 469 | - return ''; |
|
| 483 | + if ($block->type != 'function') { |
|
| 484 | + return ''; |
|
| 485 | + } |
|
| 470 | 486 | |
| 471 | 487 | $code = apply(pipe( |
| 472 | 488 | _f('code_from_description'), |
@@ -480,8 +496,9 @@ discard block |
||
| 480 | 496 | join("\n") |
| 481 | 497 | ), [$block]); |
| 482 | 498 | |
| 483 | - if ('' == trim($code)) |
|
| 484 | - return ''; |
|
| 499 | + if ('' == trim($code)) { |
|
| 500 | + return ''; |
|
| 501 | + } |
|
| 485 | 502 | return prepend("\tpublic function test_{$block->name}() {\n", |
| 486 | 503 | append("\n\t}\n", $code) |
| 487 | 504 | ); |
@@ -496,8 +513,9 @@ discard block |
||
| 496 | 513 | */ |
| 497 | 514 | function code_from_description($block) { |
| 498 | 515 | $description = get('description', $block); |
| 499 | - if (!contains('```php', $description)) |
|
| 500 | - return ''; |
|
| 516 | + if (!contains('```php', $description)) { |
|
| 517 | + return ''; |
|
| 518 | + } |
|
| 501 | 519 | $code = remove(7 + indexOf('```php', $description), $description); |
| 502 | 520 | return remove(-4, trim($code)); |
| 503 | 521 | } |
@@ -513,8 +531,7 @@ discard block |
||
| 513 | 531 | if (contains('; //=> ', $part)) { |
| 514 | 532 | $pieces = split('; //=> ', $part); |
| 515 | 533 | $part = "\$this->assertEquals({$pieces[1]}, {$pieces[0]});"; |
| 516 | - } |
|
| 517 | - elseif (contains('; // throws ', $part)) { |
|
| 534 | + } elseif (contains('; // throws ', $part)) { |
|
| 518 | 535 | $pieces = split('; // throws ', $part); |
| 519 | 536 | $variables = match('/ \$[0-9a-zA-Z_]+/', $pieces[0]); |
| 520 | 537 | $use = ''; |
@@ -523,8 +540,7 @@ discard block |
||
| 523 | 540 | $use = "use({$variables}) "; |
| 524 | 541 | } |
| 525 | 542 | return "\$this->assertErrorThrown(function() {$use}{\n\t$pieces[0]; \n},\n{$pieces[1]});"; |
| 526 | - } |
|
| 527 | - elseif (startsWith('class ', $part) || startsWith('function ', $part)) { |
|
| 543 | + } elseif (startsWith('class ', $part) || startsWith('function ', $part)) { |
|
| 528 | 544 | $module->testsFooter .= $part . "\n\n"; |
| 529 | 545 | $part = ''; |
| 530 | 546 | } |
@@ -539,8 +555,9 @@ discard block |
||
| 539 | 555 | * @return object |
| 540 | 556 | */ |
| 541 | 557 | function generate_tests_footer($module) { |
| 542 | - if ($module->tests) |
|
| 543 | - $module->tests .= "}\n\n{$module->testsFooter}"; |
|
| 558 | + if ($module->tests) { |
|
| 559 | + $module->tests .= "}\n\n{$module->testsFooter}"; |
|
| 560 | + } |
|
| 544 | 561 | return $module; |
| 545 | 562 | } |
| 546 | 563 | |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | function filter() { |
| 68 | 68 | static $filter = false; |
| 69 | - $filter = $filter ?: curry(function($fn, $list){ |
|
| 69 | + $filter = $filter ?: curry(function($fn, $list) { |
|
| 70 | 70 | return array_values(array_filter($list, $fn)); |
| 71 | 71 | }); |
| 72 | 72 | return _apply($filter, func_get_args()); |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | */ |
| 92 | 92 | function reduce() { |
| 93 | 93 | static $reduce = false; |
| 94 | - $reduce = $reduce ?: curry(function($fn, $initial, $list){ |
|
| 94 | + $reduce = $reduce ?: curry(function($fn, $initial, $list) { |
|
| 95 | 95 | return array_reduce($list, $fn, $initial); |
| 96 | 96 | }); |
| 97 | 97 | return _apply($reduce, func_get_args()); |
@@ -118,7 +118,7 @@ discard block |
||
| 118 | 118 | */ |
| 119 | 119 | function each() { |
| 120 | 120 | static $each = false; |
| 121 | - $each = $each ?: curry(function($fn, $list){ |
|
| 121 | + $each = $each ?: curry(function($fn, $list) { |
|
| 122 | 122 | foreach ($list as $item) { |
| 123 | 123 | apply($fn, [$item]); |
| 124 | 124 | } |
@@ -146,7 +146,7 @@ discard block |
||
| 146 | 146 | function head() { |
| 147 | 147 | static $head = false; |
| 148 | 148 | $head = $head ?: curry(function($list) { |
| 149 | - if(is_string($list)) |
|
| 149 | + if (is_string($list)) |
|
| 150 | 150 | return substr($list, 0, 1); |
| 151 | 151 | return (count($list) > 0) |
| 152 | 152 | ? $list[0] |
@@ -171,10 +171,10 @@ discard block |
||
| 171 | 171 | * @param array|string $list |
| 172 | 172 | * @return mixed |
| 173 | 173 | */ |
| 174 | -function last () { |
|
| 174 | +function last() { |
|
| 175 | 175 | static $last = false; |
| 176 | 176 | $last = $last ?: curry(function($list) { |
| 177 | - if(is_string($list)) |
|
| 177 | + if (is_string($list)) |
|
| 178 | 178 | return substr($list, -1); |
| 179 | 179 | return (count($list) > 0) |
| 180 | 180 | ? $list[count($list) - 1] |
@@ -200,10 +200,10 @@ discard block |
||
| 200 | 200 | * @param array|string $list |
| 201 | 201 | * @return array |
| 202 | 202 | */ |
| 203 | -function init () { |
|
| 203 | +function init() { |
|
| 204 | 204 | static $init = false; |
| 205 | 205 | $init = $init ?: curry(function($list) { |
| 206 | - if(is_string($list)) |
|
| 206 | + if (is_string($list)) |
|
| 207 | 207 | return (strlen($list) > 1) |
| 208 | 208 | ? substr($list, 0, strlen($list) - 1) |
| 209 | 209 | : ''; |
@@ -231,10 +231,10 @@ discard block |
||
| 231 | 231 | * @param array|string $list |
| 232 | 232 | * @return array |
| 233 | 233 | */ |
| 234 | -function tail () { |
|
| 234 | +function tail() { |
|
| 235 | 235 | static $tail = false; |
| 236 | 236 | $tail = $tail ?: curry(function($list) { |
| 237 | - if(is_string($list)) |
|
| 237 | + if (is_string($list)) |
|
| 238 | 238 | return (strlen($list) > 1) |
| 239 | 239 | ? substr($list, 1) |
| 240 | 240 | : ''; |
@@ -259,7 +259,7 @@ discard block |
||
| 259 | 259 | * @param array|string $list |
| 260 | 260 | * @return array |
| 261 | 261 | */ |
| 262 | -function reverse () { |
|
| 262 | +function reverse() { |
|
| 263 | 263 | static $reverse = false; |
| 264 | 264 | $reverse = $reverse ?: curry(function($list) { |
| 265 | 265 | return is_string($list) |
@@ -382,8 +382,7 @@ discard block |
||
| 382 | 382 | function concatAll() { |
| 383 | 383 | static $concatAll = false; |
| 384 | 384 | $concatAll = $concatAll ?: curry(function($lists) { |
| 385 | - return length($lists) == 0 ? [] : |
|
| 386 | - reduce(concat(), head($lists), tail($lists)); |
|
| 385 | + return length($lists) == 0 ? [] : reduce(concat(), head($lists), tail($lists)); |
|
| 387 | 386 | }); |
| 388 | 387 | return _apply($concatAll, func_get_args()); |
| 389 | 388 | } |
@@ -471,7 +470,7 @@ discard block |
||
| 471 | 470 | */ |
| 472 | 471 | function append() { |
| 473 | 472 | static $append = false; |
| 474 | - $append = $append ?: curry(function ($item, $list) { |
|
| 473 | + $append = $append ?: curry(function($item, $list) { |
|
| 475 | 474 | return insert(length($list), $item, $list); |
| 476 | 475 | }); |
| 477 | 476 | return _apply($append, func_get_args()); |
@@ -523,7 +522,7 @@ discard block |
||
| 523 | 522 | $length = length($list); |
| 524 | 523 | if ($count > $length || $count < -$length) |
| 525 | 524 | return []; |
| 526 | - if(is_string($list)) { |
|
| 525 | + if (is_string($list)) { |
|
| 527 | 526 | return ($count >= 0) |
| 528 | 527 | ? substr($list, 0, $count) |
| 529 | 528 | : substr($list, $count); |
@@ -812,9 +811,9 @@ discard block |
||
| 812 | 811 | function slices() { |
| 813 | 812 | static $slices = false; |
| 814 | 813 | $slices = $slices ?: curry(function($size, $list) { |
| 815 | - if(empty($list)) |
|
| 814 | + if (empty($list)) |
|
| 816 | 815 | return is_string($list) ? '' : []; |
| 817 | - if(length($list) <= $size) |
|
| 816 | + if (length($list) <= $size) |
|
| 818 | 817 | return [$list]; |
| 819 | 818 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 820 | 819 | }); |
@@ -841,7 +840,7 @@ discard block |
||
| 841 | 840 | function contains() { |
| 842 | 841 | static $contains = false; |
| 843 | 842 | $contains = $contains ?: curry(function($item, $list) { |
| 844 | - return -1 != indexOf($item, $list); |
|
| 843 | + return - 1 != indexOf($item, $list); |
|
| 845 | 844 | }); |
| 846 | 845 | return _apply($contains, func_get_args()); |
| 847 | 846 | } |
@@ -896,7 +895,7 @@ discard block |
||
| 896 | 895 | static $findLastIndex = false; |
| 897 | 896 | $findLastIndex = $findLastIndex ?: curry(function($predicate, $list) { |
| 898 | 897 | foreach (reverse(toPairs($list)) as $pair) { |
| 899 | - if($predicate($pair[1])) |
|
| 898 | + if ($predicate($pair[1])) |
|
| 900 | 899 | return $pair[0]; |
| 901 | 900 | } |
| 902 | 901 | return null; |
@@ -983,7 +982,7 @@ discard block |
||
| 983 | 982 | $index = findIndex(equals($item), $list); |
| 984 | 983 | } |
| 985 | 984 | return (false === $index || null === $index) |
| 986 | - ? -1 |
|
| 985 | + ? - 1 |
|
| 987 | 986 | : $index; |
| 988 | 987 | }); |
| 989 | 988 | return _apply($indexOf, func_get_args()); |
@@ -1016,7 +1015,7 @@ discard block |
||
| 1016 | 1015 | $index = findLastIndex(equals($item), $list); |
| 1017 | 1016 | } |
| 1018 | 1017 | return (false === $index || null === $index) |
| 1019 | - ? -1 |
|
| 1018 | + ? - 1 |
|
| 1020 | 1019 | : $index; |
| 1021 | 1020 | }); |
| 1022 | 1021 | return _apply($lastIndexOf, func_get_args()); |
@@ -1107,7 +1106,7 @@ discard block |
||
| 1107 | 1106 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
| 1108 | 1107 | return reduce(function($result, $item) use($fn) { |
| 1109 | 1108 | $index = $fn($item); |
| 1110 | - if (! isset($result[$index])) |
|
| 1109 | + if (!isset($result[$index])) |
|
| 1111 | 1110 | $result[$index] = []; |
| 1112 | 1111 | $result[$index][] = $item; |
| 1113 | 1112 | return $result; |
@@ -146,8 +146,9 @@ discard block |
||
| 146 | 146 | function head() { |
| 147 | 147 | static $head = false; |
| 148 | 148 | $head = $head ?: curry(function($list) { |
| 149 | - if(is_string($list)) |
|
| 150 | - return substr($list, 0, 1); |
|
| 149 | + if(is_string($list)) { |
|
| 150 | + return substr($list, 0, 1); |
|
| 151 | + } |
|
| 151 | 152 | return (count($list) > 0) |
| 152 | 153 | ? $list[0] |
| 153 | 154 | : null; |
@@ -174,8 +175,9 @@ discard block |
||
| 174 | 175 | function last () { |
| 175 | 176 | static $last = false; |
| 176 | 177 | $last = $last ?: curry(function($list) { |
| 177 | - if(is_string($list)) |
|
| 178 | - return substr($list, -1); |
|
| 178 | + if(is_string($list)) { |
|
| 179 | + return substr($list, -1); |
|
| 180 | + } |
|
| 179 | 181 | return (count($list) > 0) |
| 180 | 182 | ? $list[count($list) - 1] |
| 181 | 183 | : null; |
@@ -203,10 +205,11 @@ discard block |
||
| 203 | 205 | function init () { |
| 204 | 206 | static $init = false; |
| 205 | 207 | $init = $init ?: curry(function($list) { |
| 206 | - if(is_string($list)) |
|
| 207 | - return (strlen($list) > 1) |
|
| 208 | + if(is_string($list)) { |
|
| 209 | + return (strlen($list) > 1) |
|
| 208 | 210 | ? substr($list, 0, strlen($list) - 1) |
| 209 | 211 | : ''; |
| 212 | + } |
|
| 210 | 213 | return (count($list) > 1) |
| 211 | 214 | ? array_slice($list, 0, count($list) - 1) |
| 212 | 215 | : []; |
@@ -234,10 +237,11 @@ discard block |
||
| 234 | 237 | function tail () { |
| 235 | 238 | static $tail = false; |
| 236 | 239 | $tail = $tail ?: curry(function($list) { |
| 237 | - if(is_string($list)) |
|
| 238 | - return (strlen($list) > 1) |
|
| 240 | + if(is_string($list)) { |
|
| 241 | + return (strlen($list) > 1) |
|
| 239 | 242 | ? substr($list, 1) |
| 240 | 243 | : ''; |
| 244 | + } |
|
| 241 | 245 | return (count($list) > 1) |
| 242 | 246 | ? array_slice($list, 1) |
| 243 | 247 | : []; |
@@ -359,8 +363,9 @@ discard block |
||
| 359 | 363 | $concat = $concat ?: curry(function($list1, $list2) { |
| 360 | 364 | $t1 = toString($list1); |
| 361 | 365 | $t2 = toString($list2); |
| 362 | - if (is_string($list1) && is_string($list2)) |
|
| 363 | - return $list1 . $list2; |
|
| 366 | + if (is_string($list1) && is_string($list2)) { |
|
| 367 | + return $list1 . $list2; |
|
| 368 | + } |
|
| 364 | 369 | return array_merge($list1, $list2); |
| 365 | 370 | }); |
| 366 | 371 | return _apply($concat, func_get_args()); |
@@ -443,10 +448,12 @@ discard block |
||
| 443 | 448 | static $insertAll = false; |
| 444 | 449 | $insertAll = $insertAll ?: curry(function($position, $items, $list) { |
| 445 | 450 | $length = length($list); |
| 446 | - if ($position < 0) |
|
| 447 | - $position = $length + $position; |
|
| 448 | - if ($position < 0) |
|
| 449 | - $position = 0; |
|
| 451 | + if ($position < 0) { |
|
| 452 | + $position = $length + $position; |
|
| 453 | + } |
|
| 454 | + if ($position < 0) { |
|
| 455 | + $position = 0; |
|
| 456 | + } |
|
| 450 | 457 | return ($position >= $length) |
| 451 | 458 | ? concat($list, $items) |
| 452 | 459 | : concatAll([take($position, $list), $items, remove($position, $list)]); |
@@ -521,8 +528,9 @@ discard block |
||
| 521 | 528 | static $take = false; |
| 522 | 529 | $take = $take ?: curry(function($count, $list) { |
| 523 | 530 | $length = length($list); |
| 524 | - if ($count > $length || $count < -$length) |
|
| 525 | - return []; |
|
| 531 | + if ($count > $length || $count < -$length) { |
|
| 532 | + return []; |
|
| 533 | + } |
|
| 526 | 534 | if(is_string($list)) { |
| 527 | 535 | return ($count >= 0) |
| 528 | 536 | ? substr($list, 0, $count) |
@@ -662,8 +670,9 @@ discard block |
||
| 662 | 670 | static $remove = false; |
| 663 | 671 | $remove = $remove ?: curry(function($count, $list) { |
| 664 | 672 | $length = length($list); |
| 665 | - if ($count > $length || $count < -$length) |
|
| 666 | - return []; |
|
| 673 | + if ($count > $length || $count < -$length) { |
|
| 674 | + return []; |
|
| 675 | + } |
|
| 667 | 676 | return ($count > 0) |
| 668 | 677 | ? take($count - $length, $list) |
| 669 | 678 | : take($count + $length, $list); |
@@ -812,10 +821,12 @@ discard block |
||
| 812 | 821 | function slices() { |
| 813 | 822 | static $slices = false; |
| 814 | 823 | $slices = $slices ?: curry(function($size, $list) { |
| 815 | - if(empty($list)) |
|
| 816 | - return is_string($list) ? '' : []; |
|
| 817 | - if(length($list) <= $size) |
|
| 818 | - return [$list]; |
|
| 824 | + if(empty($list)) { |
|
| 825 | + return is_string($list) ? '' : []; |
|
| 826 | + } |
|
| 827 | + if(length($list) <= $size) { |
|
| 828 | + return [$list]; |
|
| 829 | + } |
|
| 819 | 830 | return prepend(take($size, $list), slices($size, remove($size, $list))); |
| 820 | 831 | }); |
| 821 | 832 | return _apply($slices, func_get_args()); |
@@ -867,8 +878,9 @@ discard block |
||
| 867 | 878 | static $findIndex = false; |
| 868 | 879 | $findIndex = $findIndex ?: curry(function($predicate, $list) { |
| 869 | 880 | foreach ($list as $key => $value) { |
| 870 | - if ($predicate($value)) |
|
| 871 | - return $key; |
|
| 881 | + if ($predicate($value)) { |
|
| 882 | + return $key; |
|
| 883 | + } |
|
| 872 | 884 | } |
| 873 | 885 | return null; |
| 874 | 886 | }); |
@@ -896,8 +908,9 @@ discard block |
||
| 896 | 908 | static $findLastIndex = false; |
| 897 | 909 | $findLastIndex = $findLastIndex ?: curry(function($predicate, $list) { |
| 898 | 910 | foreach (reverse(toPairs($list)) as $pair) { |
| 899 | - if($predicate($pair[1])) |
|
| 900 | - return $pair[0]; |
|
| 911 | + if($predicate($pair[1])) { |
|
| 912 | + return $pair[0]; |
|
| 913 | + } |
|
| 901 | 914 | } |
| 902 | 915 | return null; |
| 903 | 916 | }); |
@@ -1107,8 +1120,9 @@ discard block |
||
| 1107 | 1120 | $groupBy = $groupBy ?: curry(function($fn, $list) { |
| 1108 | 1121 | return reduce(function($result, $item) use($fn) { |
| 1109 | 1122 | $index = $fn($item); |
| 1110 | - if (! isset($result[$index])) |
|
| 1111 | - $result[$index] = []; |
|
| 1123 | + if (! isset($result[$index])) { |
|
| 1124 | + $result[$index] = []; |
|
| 1125 | + } |
|
| 1112 | 1126 | $result[$index][] = $item; |
| 1113 | 1127 | return $result; |
| 1114 | 1128 | }, [], $list); |
@@ -1137,8 +1151,9 @@ discard block |
||
| 1137 | 1151 | $pairsFrom = $pairsFrom ?: curry(function($list1, $list2) { |
| 1138 | 1152 | $length1 = length($list1); |
| 1139 | 1153 | $length2 = length($list2); |
| 1140 | - if (0 == $length1 || 0 == $length2) |
|
| 1141 | - return []; |
|
| 1154 | + if (0 == $length1 || 0 == $length2) { |
|
| 1155 | + return []; |
|
| 1156 | + } |
|
| 1142 | 1157 | $list1 = values($list1); |
| 1143 | 1158 | $list2 = values($list2); |
| 1144 | 1159 | return map(function($index) use($list1, $list2) { |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | */ |
| 41 | 41 | function join() { |
| 42 | 42 | static $join = false; |
| 43 | - $join = $join ?: curry(function($glue, $pieces){ |
|
| 43 | + $join = $join ?: curry(function($glue, $pieces) { |
|
| 44 | 44 | return implode($glue, $pieces); |
| 45 | 45 | }); |
| 46 | 46 | return _apply($join, func_get_args()); |
@@ -358,8 +358,7 @@ discard block |
||
| 358 | 358 | $updateCountAt = curry(function($item, $counts, $index) use($openings, $closings) { |
| 359 | 359 | $count = occurences(__(), $item); |
| 360 | 360 | return ($openings[$index] == $closings[$index]) ? |
| 361 | - ($counts[$index] + $count($openings[$index])) % 2 : |
|
| 362 | - $counts[$index] + $count($openings[$index]) - $count($closings[$index]); |
|
| 361 | + ($counts[$index] + $count($openings[$index])) % 2 : $counts[$index] + $count($openings[$index]) - $count($closings[$index]); |
|
| 363 | 362 | }); |
| 364 | 363 | // Updates counts for all surrenders |
| 365 | 364 | $updateCounts = curry(function($item, $counts) use($indexes, $updateCountAt) { |
@@ -20,7 +20,7 @@ discard block |
||
| 20 | 20 | */ |
| 21 | 21 | function plus() { |
| 22 | 22 | static $plus = false; |
| 23 | - $plus = $plus ?: curry(function($x, $y){ |
|
| 23 | + $plus = $plus ?: curry(function($x, $y) { |
|
| 24 | 24 | return $x + $y; |
| 25 | 25 | }); |
| 26 | 26 | return _apply($plus, func_get_args()); |
@@ -41,7 +41,7 @@ discard block |
||
| 41 | 41 | */ |
| 42 | 42 | function minus() { |
| 43 | 43 | static $minus = false; |
| 44 | - $minus = $minus ?: curry(function($x, $y){ |
|
| 44 | + $minus = $minus ?: curry(function($x, $y) { |
|
| 45 | 45 | return $x - $y; |
| 46 | 46 | }); |
| 47 | 47 | return _apply($minus, func_get_args()); |
@@ -62,8 +62,8 @@ discard block |
||
| 62 | 62 | */ |
| 63 | 63 | function negate() { |
| 64 | 64 | static $negate = false; |
| 65 | - $negate = $negate ?: curry(function($x){ |
|
| 66 | - return -$x; |
|
| 65 | + $negate = $negate ?: curry(function($x) { |
|
| 66 | + return - $x; |
|
| 67 | 67 | }); |
| 68 | 68 | return _apply($negate, func_get_args()); |
| 69 | 69 | } |
@@ -84,7 +84,7 @@ discard block |
||
| 84 | 84 | */ |
| 85 | 85 | function multiply() { |
| 86 | 86 | static $multiply = false; |
| 87 | - $multiply = $multiply ?: curry(function($x, $y){ |
|
| 87 | + $multiply = $multiply ?: curry(function($x, $y) { |
|
| 88 | 88 | return $y * $x; |
| 89 | 89 | }); |
| 90 | 90 | return _apply($multiply, func_get_args()); |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | */ |
| 106 | 106 | function divide() { |
| 107 | 107 | static $divide = false; |
| 108 | - $divide = $divide ?: curry(function($x, $y){ |
|
| 108 | + $divide = $divide ?: curry(function($x, $y) { |
|
| 109 | 109 | return $x / $y; |
| 110 | 110 | }); |
| 111 | 111 | return _apply($divide, func_get_args()); |
@@ -126,7 +126,7 @@ discard block |
||
| 126 | 126 | */ |
| 127 | 127 | function modulo() { |
| 128 | 128 | static $modulo = false; |
| 129 | - $modulo = $modulo ?: curry(function($x, $y){ |
|
| 129 | + $modulo = $modulo ?: curry(function($x, $y) { |
|
| 130 | 130 | return $x % $y; |
| 131 | 131 | }); |
| 132 | 132 | return _apply($modulo, func_get_args()); |
@@ -147,7 +147,7 @@ discard block |
||
| 147 | 147 | */ |
| 148 | 148 | function sum() { |
| 149 | 149 | static $sum = false; |
| 150 | - $sum = $sum ?: curry(function($numbers){ |
|
| 150 | + $sum = $sum ?: curry(function($numbers) { |
|
| 151 | 151 | return reduce(plus(), 0, $numbers); |
| 152 | 152 | }); |
| 153 | 153 | return _apply($sum, func_get_args()); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | */ |
| 169 | 169 | function product() { |
| 170 | 170 | static $product = false; |
| 171 | - $product = $product ?: curry(function($numbers){ |
|
| 171 | + $product = $product ?: curry(function($numbers) { |
|
| 172 | 172 | return reduce(multiply(), 1, $numbers); |
| 173 | 173 | }); |
| 174 | 174 | return _apply($product, func_get_args()); |
@@ -190,7 +190,7 @@ discard block |
||
| 190 | 190 | */ |
| 191 | 191 | function min() { |
| 192 | 192 | static $min = false; |
| 193 | - $min = $min ?: curry(function($a, $b){ |
|
| 193 | + $min = $min ?: curry(function($a, $b) { |
|
| 194 | 194 | return $a < $b ? $a : $b; |
| 195 | 195 | }); |
| 196 | 196 | return _apply($min, func_get_args()); |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | */ |
| 214 | 214 | function minBy() { |
| 215 | 215 | static $minBy = false; |
| 216 | - $minBy = $minBy ?: curry(function($fn, $a, $b){ |
|
| 216 | + $minBy = $minBy ?: curry(function($fn, $a, $b) { |
|
| 217 | 217 | return $fn($a) < $fn($b) ? $a : $b; |
| 218 | 218 | }); |
| 219 | 219 | return _apply($minBy, func_get_args()); |
@@ -235,7 +235,7 @@ discard block |
||
| 235 | 235 | */ |
| 236 | 236 | function max() { |
| 237 | 237 | static $max = false; |
| 238 | - $max = $max ?: curry(function($a, $b){ |
|
| 238 | + $max = $max ?: curry(function($a, $b) { |
|
| 239 | 239 | return $a > $b ? $a : $b; |
| 240 | 240 | }); |
| 241 | 241 | return _apply($max, func_get_args()); |
@@ -258,7 +258,7 @@ discard block |
||
| 258 | 258 | */ |
| 259 | 259 | function maxBy() { |
| 260 | 260 | static $maxBy = false; |
| 261 | - $maxBy = $maxBy ?: curry(function($fn, $a, $b){ |
|
| 261 | + $maxBy = $maxBy ?: curry(function($fn, $a, $b) { |
|
| 262 | 262 | return $fn($a) > $fn($b) ? $a : $b; |
| 263 | 263 | }); |
| 264 | 264 | return _apply($maxBy, func_get_args()); |
@@ -32,8 +32,7 @@ discard block |
||
| 32 | 32 | */ |
| 33 | 33 | function _number_of_args($fn) { |
| 34 | 34 | $reflector = is_array($fn) ? |
| 35 | - new \ReflectionMethod($fn[0], $fn[1]) : |
|
| 36 | - new \ReflectionFunction($fn); |
|
| 35 | + new \ReflectionMethod($fn[0], $fn[1]) : new \ReflectionFunction($fn); |
|
| 37 | 36 | return $reflector->getNumberOfRequiredParameters(); |
| 38 | 37 | } |
| 39 | 38 | |
@@ -65,7 +64,7 @@ discard block |
||
| 65 | 64 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 66 | 65 | $currentBoundArgsCount = count($currentBoundArgs); |
| 67 | 66 | $placeholderPosition = 0; |
| 68 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 67 | + while ($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 69 | 68 | $placeholderPosition ++; |
| 70 | 69 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 71 | 70 | $currentBoundArgs[] = $arg; |
@@ -65,8 +65,9 @@ discard block |
||
| 65 | 65 | $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) { |
| 66 | 66 | $currentBoundArgsCount = count($currentBoundArgs); |
| 67 | 67 | $placeholderPosition = 0; |
| 68 | - while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) |
|
| 69 | - $placeholderPosition ++; |
|
| 68 | + while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) { |
|
| 69 | + $placeholderPosition ++; |
|
| 70 | + } |
|
| 70 | 71 | if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) { |
| 71 | 72 | $currentBoundArgs[] = $arg; |
| 72 | 73 | } else { // There is a placeholder and number of bound args >= $fnArgsCount |
@@ -92,8 +93,9 @@ discard block |
||
| 92 | 93 | $boundArgs = _merge_args($argsCount, $boundArgs, func_get_args()); |
| 93 | 94 | $numberOfPlaceholders = count(array_filter($boundArgs, _f('_is_placeholder'))); |
| 94 | 95 | $numberOfGivenArgs = count($boundArgs) - $numberOfPlaceholders; |
| 95 | - if ($numberOfGivenArgs >= $argsCount) |
|
| 96 | - return call_user_func_array($fn, $boundArgs); |
|
| 96 | + if ($numberOfGivenArgs >= $argsCount) { |
|
| 97 | + return call_user_func_array($fn, $boundArgs); |
|
| 98 | + } |
|
| 97 | 99 | return _curried_function($fn, $argsCount, $boundArgs); |
| 98 | 100 | }; |
| 99 | 101 | } |
@@ -166,7 +166,7 @@ discard block |
||
| 166 | 166 | if (length($parts) < 2) |
| 167 | 167 | _stream_throw_error('invalid-signature', $text); |
| 168 | 168 | |
| 169 | - return reduce(function($result, $part){ |
|
| 169 | + return reduce(function($result, $part) { |
|
| 170 | 170 | return chain(function($item) use($result){ |
| 171 | 171 | return map(append($item), $result); |
| 172 | 172 | }, $part); |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | */ |
| 197 | 197 | function _stream_ensure_type() { |
| 198 | 198 | $ensureType = function($signature, $type) { |
| 199 | - if (! contains($type, _stream_types())) |
|
| 199 | + if (!contains($type, _stream_types())) |
|
| 200 | 200 | _stream_throw_error('invalid-signature', $signature); |
| 201 | 201 | return $type; |
| 202 | 202 | }; |
@@ -571,7 +571,7 @@ discard block |
||
| 571 | 571 | $args = append(get('data', $stream), get('args', $transformation)); |
| 572 | 572 | $argsTypes = map(type(), $args); |
| 573 | 573 | $operation = get('operation', $transformation); |
| 574 | - if (! _stream_operation_is_applicable($argsTypes, $operation)) { |
|
| 574 | + if (!_stream_operation_is_applicable($argsTypes, $operation)) { |
|
| 575 | 575 | _stream_throw_error('wrong-transformation-args', $operation['name'], $argsTypes, init(head(get('signatures', $operation)))); |
| 576 | 576 | } |
| 577 | 577 | |
@@ -131,8 +131,9 @@ discard block |
||
| 131 | 131 | */ |
| 132 | 132 | function _stream_operation($name, $signature, $callable = null) { |
| 133 | 133 | $callable = $callable ?: $name; |
| 134 | - if (!is_callable($callable)) |
|
| 135 | - _stream_throw_error('unknown-callable', $callable); |
|
| 134 | + if (!is_callable($callable)) { |
|
| 135 | + _stream_throw_error('unknown-callable', $callable); |
|
| 136 | + } |
|
| 136 | 137 | |
| 137 | 138 | return [ |
| 138 | 139 | 'name' => $name, |
@@ -163,8 +164,9 @@ discard block |
||
| 163 | 164 | // Assuming $text = 'Number|List -> Number -> String|Array -> Number' |
| 164 | 165 | $parts = map(pipe(split('|'), map(pipe('trim', _stream_ensure_type($text)))), split('->', $text)); |
| 165 | 166 | // $parts = [['Number', 'List'], ['Number'], ['String', 'Array'], ['Number']] |
| 166 | - if (length($parts) < 2) |
|
| 167 | - _stream_throw_error('invalid-signature', $text); |
|
| 167 | + if (length($parts) < 2) { |
|
| 168 | + _stream_throw_error('invalid-signature', $text); |
|
| 169 | + } |
|
| 168 | 170 | |
| 169 | 171 | return reduce(function($result, $part){ |
| 170 | 172 | return chain(function($item) use($result){ |
@@ -196,8 +198,9 @@ discard block |
||
| 196 | 198 | */ |
| 197 | 199 | function _stream_ensure_type() { |
| 198 | 200 | $ensureType = function($signature, $type) { |
| 199 | - if (! contains($type, _stream_types())) |
|
| 200 | - _stream_throw_error('invalid-signature', $signature); |
|
| 201 | + if (! contains($type, _stream_types())) { |
|
| 202 | + _stream_throw_error('invalid-signature', $signature); |
|
| 203 | + } |
|
| 201 | 204 | return $type; |
| 202 | 205 | }; |
| 203 | 206 | return apply(curry($ensureType), func_get_args()); |
@@ -553,8 +556,9 @@ discard block |
||
| 553 | 556 | * @return array |
| 554 | 557 | */ |
| 555 | 558 | function _stream_resolve($stream) { |
| 556 | - if (get('resolved', $stream)) |
|
| 557 | - return $stream; |
|
| 559 | + if (get('resolved', $stream)) { |
|
| 560 | + return $stream; |
|
| 561 | + } |
|
| 558 | 562 | $transformations = get('transformations', $stream); |
| 559 | 563 | $transformation = head($transformations); |
| 560 | 564 | if (null === $transformation) { |