@@ -64,8 +64,6 @@ |
||
64 | 64 | * ``` |
65 | 65 | * |
66 | 66 | * @signature (*... -> a) -> [*] -> a |
67 | - * @param callable $fn |
|
68 | - * @param array $args |
|
69 | 67 | * @return mixed |
70 | 68 | */ |
71 | 69 | function apply() { |
@@ -91,9 +91,9 @@ |
||
91 | 91 | */ |
92 | 92 | function pipe() { |
93 | 93 | $fns = func_get_args(); |
94 | - if(count($fns) < 1) |
|
94 | + if (count($fns) < 1) |
|
95 | 95 | throw new InvalidArgument("pipe() requires at least one argument"); |
96 | - return curry(function () use ($fns) { |
|
96 | + return curry(function() use ($fns) { |
|
97 | 97 | $result = _apply(array_shift($fns), func_get_args()); |
98 | 98 | foreach ($fns as $fn) { |
99 | 99 | $result = $fn($result); |
@@ -91,8 +91,9 @@ |
||
91 | 91 | */ |
92 | 92 | function pipe() { |
93 | 93 | $fns = func_get_args(); |
94 | - if(count($fns) < 1) |
|
95 | - throw new InvalidArgument("pipe() requires at least one argument"); |
|
94 | + if(count($fns) < 1) { |
|
95 | + throw new InvalidArgument("pipe() requires at least one argument"); |
|
96 | + } |
|
96 | 97 | return curry(function () use ($fns) { |
97 | 98 | $result = _apply(array_shift($fns), func_get_args()); |
98 | 99 | foreach ($fns as $fn) { |
@@ -11,8 +11,6 @@ discard block |
||
11 | 11 | * ``` |
12 | 12 | * |
13 | 13 | * @signature Number -> Number -> Number |
14 | - * @param int|float $x |
|
15 | - * @param int|float $y |
|
16 | 14 | * @return int|float |
17 | 15 | */ |
18 | 16 | function plus() { |
@@ -29,8 +27,6 @@ discard block |
||
29 | 27 | * ``` |
30 | 28 | * |
31 | 29 | * @signature Number -> Number -> Number |
32 | - * @param int|float $x |
|
33 | - * @param int|float $y |
|
34 | 30 | * @return int|float |
35 | 31 | */ |
36 | 32 | function minus() { |
@@ -63,8 +59,6 @@ discard block |
||
63 | 59 | * ``` |
64 | 60 | * |
65 | 61 | * @signature Number -> Number -> Number |
66 | - * @param int|float $x |
|
67 | - * @param int|float $y |
|
68 | 62 | * @return int|float |
69 | 63 | */ |
70 | 64 | function multiply() { |
@@ -81,8 +75,6 @@ discard block |
||
81 | 75 | * ``` |
82 | 76 | * |
83 | 77 | * @signature Number -> Number -> Number |
84 | - * @param int|float $x |
|
85 | - * @param int|float $y |
|
86 | 78 | * @return int|float |
87 | 79 | */ |
88 | 80 | function divide() { |
@@ -99,8 +91,6 @@ discard block |
||
99 | 91 | * ``` |
100 | 92 | * |
101 | 93 | * @signature Number -> Number -> Number |
102 | - * @param int|float $x |
|
103 | - * @param int|float $y |
|
104 | 94 | * @return int|float |
105 | 95 | */ |
106 | 96 | function modulo() { |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * @return int|float |
17 | 17 | */ |
18 | 18 | function plus() { |
19 | - $plus = curry(function($x, $y){ |
|
19 | + $plus = curry(function($x, $y) { |
|
20 | 20 | return $x + $y; |
21 | 21 | }); |
22 | 22 | return apply($plus, func_get_args()); |
@@ -34,7 +34,7 @@ discard block |
||
34 | 34 | * @return int|float |
35 | 35 | */ |
36 | 36 | function minus() { |
37 | - $minus = curry(function($x, $y){ |
|
37 | + $minus = curry(function($x, $y) { |
|
38 | 38 | return $x - $y; |
39 | 39 | }); |
40 | 40 | return apply($minus, func_get_args()); |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @return int|float |
53 | 53 | */ |
54 | 54 | function negate($x) { |
55 | - return -$x; |
|
55 | + return - $x; |
|
56 | 56 | } |
57 | 57 | |
58 | 58 | /** |
@@ -68,7 +68,7 @@ discard block |
||
68 | 68 | * @return int|float |
69 | 69 | */ |
70 | 70 | function multiply() { |
71 | - $multiply = curry(function($x, $y){ |
|
71 | + $multiply = curry(function($x, $y) { |
|
72 | 72 | return $y * $x; |
73 | 73 | }); |
74 | 74 | return apply($multiply, func_get_args()); |
@@ -86,7 +86,7 @@ discard block |
||
86 | 86 | * @return int|float |
87 | 87 | */ |
88 | 88 | function divide() { |
89 | - $divide = curry(function($x, $y){ |
|
89 | + $divide = curry(function($x, $y) { |
|
90 | 90 | return $x / $y; |
91 | 91 | }); |
92 | 92 | return apply($divide, func_get_args()); |
@@ -104,7 +104,7 @@ discard block |
||
104 | 104 | * @return int|float |
105 | 105 | */ |
106 | 106 | function modulo() { |
107 | - $modulo = curry(function($x, $y){ |
|
107 | + $modulo = curry(function($x, $y) { |
|
108 | 108 | return $x % $y; |
109 | 109 | }); |
110 | 110 | return apply($modulo, func_get_args()); |
@@ -8,8 +8,6 @@ discard block |
||
8 | 8 | * Returns `$a && $b`. |
9 | 9 | * |
10 | 10 | * @signature Boolean -> Boolean -> Boolean |
11 | - * @param bool $a |
|
12 | - * @param bool $b |
|
13 | 11 | * @return bool |
14 | 12 | */ |
15 | 13 | function and_() { |
@@ -22,8 +20,6 @@ discard block |
||
22 | 20 | * Returns `$a || $b`. |
23 | 21 | * |
24 | 22 | * @signature Boolean -> Boolean -> Boolean |
25 | - * @param bool $a |
|
26 | - * @param bool $b |
|
27 | 23 | * @return bool |
28 | 24 | */ |
29 | 25 | function or_() { |
@@ -47,8 +43,6 @@ discard block |
||
47 | 43 | * Returns `$x == $y`. |
48 | 44 | * |
49 | 45 | * @signature * -> * -> Boolean |
50 | - * @param mixed $a |
|
51 | - * @param mixed $b |
|
52 | 46 | * @return bool |
53 | 47 | */ |
54 | 48 | function eq() { |
@@ -61,8 +55,6 @@ discard block |
||
61 | 55 | * Returns `$x != $y`. |
62 | 56 | * |
63 | 57 | * @signature * -> * -> Boolean |
64 | - * @param mixed $a |
|
65 | - * @param mixed $b |
|
66 | 58 | * @return bool |
67 | 59 | */ |
68 | 60 | function notEq() { |
@@ -75,8 +67,6 @@ discard block |
||
75 | 67 | * Returns `$x === $y`. |
76 | 68 | * |
77 | 69 | * @signature * -> * -> Boolean |
78 | - * @param mixed $a |
|
79 | - * @param mixed $b |
|
80 | 70 | * @return bool |
81 | 71 | */ |
82 | 72 | function eqq() { |
@@ -89,8 +79,6 @@ discard block |
||
89 | 79 | * Returns `$x !== $y`. |
90 | 80 | * |
91 | 81 | * @signature * -> * -> Boolean |
92 | - * @param mixed $a |
|
93 | - * @param mixed $b |
|
94 | 82 | * @return bool |
95 | 83 | */ |
96 | 84 | function notEqq() { |
@@ -103,8 +91,6 @@ discard block |
||
103 | 91 | * Returns `$x < $y`. |
104 | 92 | * |
105 | 93 | * @signature * -> * -> Boolean |
106 | - * @param mixed $a |
|
107 | - * @param mixed $b |
|
108 | 94 | * @return bool |
109 | 95 | */ |
110 | 96 | function lt() { |
@@ -117,8 +103,6 @@ discard block |
||
117 | 103 | * Returns `$x <= $y`. |
118 | 104 | * |
119 | 105 | * @signature * -> * -> Boolean |
120 | - * @param mixed $a |
|
121 | - * @param mixed $b |
|
122 | 106 | * @return bool |
123 | 107 | */ |
124 | 108 | function lte() { |
@@ -131,8 +115,6 @@ discard block |
||
131 | 115 | * Returns `$x > $y`. |
132 | 116 | * |
133 | 117 | * @signature * -> * -> Boolean |
134 | - * @param mixed $a |
|
135 | - * @param mixed $b |
|
136 | 118 | * @return bool |
137 | 119 | */ |
138 | 120 | function gt() { |
@@ -145,8 +127,6 @@ discard block |
||
145 | 127 | * Returns `$x >= $y`. |
146 | 128 | * |
147 | 129 | * @signature * -> * -> Boolean |
148 | - * @param mixed $a |
|
149 | - * @param mixed $b |
|
150 | 130 | * @return bool |
151 | 131 | */ |
152 | 132 | function gte() { |
@@ -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 | } |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @return bool |
53 | 53 | */ |
54 | 54 | function eq() { |
55 | - return apply(curry(function($a, $b){ |
|
55 | + return apply(curry(function($a, $b) { |
|
56 | 56 | return $a == $b; |
57 | 57 | }), func_get_args()); |
58 | 58 | } |
@@ -66,7 +66,7 @@ discard block |
||
66 | 66 | * @return bool |
67 | 67 | */ |
68 | 68 | function notEq() { |
69 | - return apply(curry(function($a, $b){ |
|
69 | + return apply(curry(function($a, $b) { |
|
70 | 70 | return $a != $b; |
71 | 71 | }), func_get_args()); |
72 | 72 | } |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | * @return bool |
81 | 81 | */ |
82 | 82 | function eqq() { |
83 | - return apply(curry(function($a, $b){ |
|
83 | + return apply(curry(function($a, $b) { |
|
84 | 84 | return $a === $b; |
85 | 85 | }), func_get_args()); |
86 | 86 | } |
@@ -94,7 +94,7 @@ discard block |
||
94 | 94 | * @return bool |
95 | 95 | */ |
96 | 96 | function notEqq() { |
97 | - return apply(curry(function($a, $b){ |
|
97 | + return apply(curry(function($a, $b) { |
|
98 | 98 | return $a !== $b; |
99 | 99 | }), func_get_args()); |
100 | 100 | } |
@@ -108,7 +108,7 @@ discard block |
||
108 | 108 | * @return bool |
109 | 109 | */ |
110 | 110 | function lt() { |
111 | - return apply(curry(function($a, $b){ |
|
111 | + return apply(curry(function($a, $b) { |
|
112 | 112 | return $a < $b; |
113 | 113 | }), func_get_args()); |
114 | 114 | } |
@@ -122,7 +122,7 @@ discard block |
||
122 | 122 | * @return bool |
123 | 123 | */ |
124 | 124 | function lte() { |
125 | - return apply(curry(function($a, $b){ |
|
125 | + return apply(curry(function($a, $b) { |
|
126 | 126 | return $a <= $b; |
127 | 127 | }), func_get_args()); |
128 | 128 | } |
@@ -136,7 +136,7 @@ discard block |
||
136 | 136 | * @return bool |
137 | 137 | */ |
138 | 138 | function gt() { |
139 | - return apply(curry(function($a, $b){ |
|
139 | + return apply(curry(function($a, $b) { |
|
140 | 140 | return $a > $b; |
141 | 141 | }), func_get_args()); |
142 | 142 | } |
@@ -150,7 +150,7 @@ discard block |
||
150 | 150 | * @return bool |
151 | 151 | */ |
152 | 152 | function gte() { |
153 | - return apply(curry(function($a, $b){ |
|
153 | + return apply(curry(function($a, $b) { |
|
154 | 154 | return $a >= $b; |
155 | 155 | }), func_get_args()); |
156 | 156 | } |
@@ -94,6 +94,7 @@ discard block |
||
94 | 94 | * |
95 | 95 | * @param mixed $data |
96 | 96 | * @param array $operations |
97 | + * @param boolean $type |
|
97 | 98 | * @return Stream |
98 | 99 | */ |
99 | 100 | protected static function with ($data, $operations, $type) |
@@ -414,7 +415,6 @@ discard block |
||
414 | 415 | * |
415 | 416 | * @signature Stream(a) -> (String, ...) -> Stream(*) |
416 | 417 | * @param string $method |
417 | - * @param mixed|null $args... |
|
418 | 418 | * @return Stream |
419 | 419 | */ |
420 | 420 | public function call ($method) |
@@ -468,7 +468,6 @@ discard block |
||
468 | 468 | * |
469 | 469 | * @signature Stream(a) -> (String, ...) -> Stream(a) |
470 | 470 | * @param string $method |
471 | - * @param mixed|null $args... |
|
472 | 471 | * @return Stream |
473 | 472 | */ |
474 | 473 | public function run ($method) |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @param mixed $data |
82 | 82 | * @return Stream |
83 | 83 | */ |
84 | - public static function of ($data) |
|
84 | + public static function of($data) |
|
85 | 85 | { |
86 | 86 | $data = func_get_args(); |
87 | 87 | if (count($data) == 1) |
@@ -96,7 +96,7 @@ discard block |
||
96 | 96 | * @param array $operations |
97 | 97 | * @return Stream |
98 | 98 | */ |
99 | - protected static function with ($data, $operations, $type) |
|
99 | + protected static function with($data, $operations, $type) |
|
100 | 100 | { |
101 | 101 | return new Stream($data, $operations, $type); |
102 | 102 | } |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @param array $operations |
108 | 108 | * @return array|Error |
109 | 109 | */ |
110 | - protected static function optimize ($operations) |
|
110 | + protected static function optimize($operations) |
|
111 | 111 | { |
112 | 112 | // TODO: ... |
113 | 113 | return $operations; |
@@ -120,17 +120,17 @@ discard block |
||
120 | 120 | * @param mixed $data |
121 | 121 | * @return mixed|Error |
122 | 122 | */ |
123 | - protected static function execute ($operations, $data) |
|
123 | + protected static function execute($operations, $data) |
|
124 | 124 | { |
125 | 125 | if (length($operations) == 0) |
126 | 126 | return $data; |
127 | - $operations = apply('Tarsana\\Functional\\pipe', map(function($operation){ |
|
127 | + $operations = apply('Tarsana\\Functional\\pipe', map(function($operation) { |
|
128 | 128 | if ($operation['name'] == 'apply') { |
129 | 129 | return $operation['args']; |
130 | 130 | } |
131 | 131 | return (length($operation['args']) > 0) |
132 | - ? apply('Tarsana\\Functional\\'.$operation['name'], $operation['args']) |
|
133 | - : 'Tarsana\\Functional\\'.$operation['name']; |
|
132 | + ? apply('Tarsana\\Functional\\' . $operation['name'], $operation['args']) |
|
133 | + : 'Tarsana\\Functional\\' . $operation['name']; |
|
134 | 134 | }, $operations)); |
135 | 135 | return $operations($data); |
136 | 136 | } |
@@ -142,7 +142,7 @@ discard block |
||
142 | 142 | * @param string $type |
143 | 143 | * @return bool |
144 | 144 | */ |
145 | - protected static function canApply ($operation, $type) |
|
145 | + protected static function canApply($operation, $type) |
|
146 | 146 | { |
147 | 147 | return isset(Stream::$transformations[$operation]) && ( |
148 | 148 | $type == 'Unknown' || |
@@ -158,7 +158,7 @@ discard block |
||
158 | 158 | * @param string $type |
159 | 159 | * @return bool |
160 | 160 | */ |
161 | - protected static function returnOf ($operation, $type) |
|
161 | + protected static function returnOf($operation, $type) |
|
162 | 162 | { |
163 | 163 | return isset(Stream::$transformations[$operation][$type]) |
164 | 164 | ? Stream::$transformations[$operation][$type] |
@@ -173,12 +173,12 @@ discard block |
||
173 | 173 | * @param Stream $stream |
174 | 174 | * @return Stream |
175 | 175 | */ |
176 | - protected static function apply ($operation, $args, $stream) |
|
176 | + protected static function apply($operation, $args, $stream) |
|
177 | 177 | { |
178 | 178 | if ($stream->type == 'Error') { |
179 | 179 | return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}", $stream->data)); |
180 | 180 | } |
181 | - if (! Stream::canApply($operation, $stream->type)) { |
|
181 | + if (!Stream::canApply($operation, $stream->type)) { |
|
182 | 182 | $data = toString($stream->data); |
183 | 183 | return Stream::of(Error::of("Could not apply {$operation} to {$stream->type}({$data})")); |
184 | 184 | } |
@@ -194,7 +194,7 @@ discard block |
||
194 | 194 | * |
195 | 195 | * @param mixed $data |
196 | 196 | */ |
197 | - protected function __construct ($data, $operations, $type) |
|
197 | + protected function __construct($data, $operations, $type) |
|
198 | 198 | { |
199 | 199 | $this->data = $data; |
200 | 200 | $this->type = $type; |
@@ -232,7 +232,7 @@ discard block |
||
232 | 232 | * @signature Stream(a) -> a |
233 | 233 | * @return mixed |
234 | 234 | */ |
235 | - public function get () |
|
235 | + public function get() |
|
236 | 236 | { |
237 | 237 | if ($this->type == 'Error') |
238 | 238 | return $this->data; |
@@ -251,7 +251,7 @@ discard block |
||
251 | 251 | * @param callable $fn |
252 | 252 | * @return Stream |
253 | 253 | */ |
254 | - public function map (callable $fn) |
|
254 | + public function map(callable $fn) |
|
255 | 255 | { |
256 | 256 | return Stream::apply('map', [$fn], $this); |
257 | 257 | } |
@@ -268,7 +268,7 @@ discard block |
||
268 | 268 | * @param callable $predicate |
269 | 269 | * @return Stream |
270 | 270 | */ |
271 | - public function filter (callable $predicate) |
|
271 | + public function filter(callable $predicate) |
|
272 | 272 | { |
273 | 273 | return Stream::apply('filter', [$predicate], $this); |
274 | 274 | } |
@@ -286,7 +286,7 @@ discard block |
||
286 | 286 | * @param mixed $initial |
287 | 287 | * @return Stream |
288 | 288 | */ |
289 | - public function reduce ($fn, $initial) |
|
289 | + public function reduce($fn, $initial) |
|
290 | 290 | { |
291 | 291 | return Stream::apply('reduce', [$fn, $initial], $this); |
292 | 292 | } |
@@ -305,7 +305,7 @@ discard block |
||
305 | 305 | * @param callable $fn |
306 | 306 | * @return Stream |
307 | 307 | */ |
308 | - public function chain ($fn) |
|
308 | + public function chain($fn) |
|
309 | 309 | { |
310 | 310 | return Stream::apply('chain', [$fn], $this); |
311 | 311 | } |
@@ -325,7 +325,7 @@ discard block |
||
325 | 325 | * @signature Stream(String) -> Number |
326 | 326 | * @return Stream |
327 | 327 | */ |
328 | - public function length () |
|
328 | + public function length() |
|
329 | 329 | { |
330 | 330 | return Stream::apply('length', [], $this); |
331 | 331 | } |
@@ -346,7 +346,7 @@ discard block |
||
346 | 346 | * @param int $number |
347 | 347 | * @return Stream |
348 | 348 | */ |
349 | - public function take ($number) |
|
349 | + public function take($number) |
|
350 | 350 | { |
351 | 351 | return Stream::apply('take', [$number], $this); |
352 | 352 | } |
@@ -367,7 +367,7 @@ discard block |
||
367 | 367 | * @param callable $fn |
368 | 368 | * @return Stream |
369 | 369 | */ |
370 | - public function then ($fn) |
|
370 | + public function then($fn) |
|
371 | 371 | { |
372 | 372 | $result = $this; |
373 | 373 | foreach (func_get_args() as $fn) { |
@@ -417,7 +417,7 @@ discard block |
||
417 | 417 | * @param mixed|null $args... |
418 | 418 | * @return Stream |
419 | 419 | */ |
420 | - public function call ($method) |
|
420 | + public function call($method) |
|
421 | 421 | { |
422 | 422 | $args = tail(func_get_args()); |
423 | 423 | return Stream::apply('apply', function($data) use($method, $args) { |
@@ -471,7 +471,7 @@ discard block |
||
471 | 471 | * @param mixed|null $args... |
472 | 472 | * @return Stream |
473 | 473 | */ |
474 | - public function run ($method) |
|
474 | + public function run($method) |
|
475 | 475 | { |
476 | 476 | $args = tail(func_get_args()); |
477 | 477 | return Stream::apply('apply', function($data) use($method, $args) { |
@@ -84,8 +84,9 @@ discard block |
||
84 | 84 | public static function of ($data) |
85 | 85 | { |
86 | 86 | $data = func_get_args(); |
87 | - if (count($data) == 1) |
|
88 | - $data = $data[0]; |
|
87 | + if (count($data) == 1) { |
|
88 | + $data = $data[0]; |
|
89 | + } |
|
89 | 90 | return new Stream($data, [], type($data)); |
90 | 91 | } |
91 | 92 | |
@@ -122,8 +123,9 @@ discard block |
||
122 | 123 | */ |
123 | 124 | protected static function execute ($operations, $data) |
124 | 125 | { |
125 | - if (length($operations) == 0) |
|
126 | - return $data; |
|
126 | + if (length($operations) == 0) { |
|
127 | + return $data; |
|
128 | + } |
|
127 | 129 | $operations = apply('Tarsana\\Functional\\pipe', map(function($operation){ |
128 | 130 | if ($operation['name'] == 'apply') { |
129 | 131 | return $operation['args']; |
@@ -234,8 +236,9 @@ discard block |
||
234 | 236 | */ |
235 | 237 | public function get () |
236 | 238 | { |
237 | - if ($this->type == 'Error') |
|
238 | - return $this->data; |
|
239 | + if ($this->type == 'Error') { |
|
240 | + return $this->data; |
|
241 | + } |
|
239 | 242 | return Stream::execute($this->operations, $this->data); |
240 | 243 | } |
241 | 244 | |
@@ -421,11 +424,13 @@ discard block |
||
421 | 424 | { |
422 | 425 | $args = tail(func_get_args()); |
423 | 426 | return Stream::apply('apply', function($data) use($method, $args) { |
424 | - if (is_callable([$data, $method])) |
|
425 | - return call_user_func_array([$data, $method], $args); |
|
427 | + if (is_callable([$data, $method])) { |
|
428 | + return call_user_func_array([$data, $method], $args); |
|
429 | + } |
|
426 | 430 | $text = toString($data); |
427 | - if (method_exists($data, $method)) |
|
428 | - return Error::of("Method '{$method}' of {$text} is not accessible"); |
|
431 | + if (method_exists($data, $method)) { |
|
432 | + return Error::of("Method '{$method}' of {$text} is not accessible"); |
|
433 | + } |
|
429 | 434 | return Error::of("Method '{$method}' of {$text} is not found"); |
430 | 435 | }, $this); |
431 | 436 | } |
@@ -480,8 +485,9 @@ discard block |
||
480 | 485 | return $data; |
481 | 486 | } |
482 | 487 | $text = toString($data); |
483 | - if (method_exists($data, $method)) |
|
484 | - return Error::of("Method '{$method}' of {$text} is not accessible"); |
|
488 | + if (method_exists($data, $method)) { |
|
489 | + return Error::of("Method '{$method}' of {$text} is not accessible"); |
|
490 | + } |
|
485 | 491 | return Error::of("Method '{$method}' of {$text} is not found"); |
486 | 492 | }, $this); |
487 | 493 | } |
@@ -11,8 +11,6 @@ discard block |
||
11 | 11 | * ``` |
12 | 12 | * |
13 | 13 | * @signature String -> String -> [String] |
14 | - * @param string $delimiter |
|
15 | - * @param string $string |
|
16 | 14 | * @return array |
17 | 15 | */ |
18 | 16 | function split() { |
@@ -27,8 +25,6 @@ discard block |
||
27 | 25 | * ``` |
28 | 26 | * |
29 | 27 | * @signature String -> [String] -> String |
30 | - * @param string $glue |
|
31 | - * @param array $pieces |
|
32 | 28 | * @return string |
33 | 29 | */ |
34 | 30 | function join() { |
@@ -48,9 +44,6 @@ discard block |
||
48 | 44 | * ``` |
49 | 45 | * |
50 | 46 | * @signature String|[String] -> String -> String|[String] -> String |
51 | - * @param string $search |
|
52 | - * @param string $replacement |
|
53 | - * @param string $string |
|
54 | 47 | * @return string |
55 | 48 | */ |
56 | 49 | function replace() { |
@@ -66,9 +59,6 @@ discard block |
||
66 | 59 | * ``` |
67 | 60 | * |
68 | 61 | * @signature String -> String -> String -> String |
69 | - * @param string $pattern |
|
70 | - * @param string $replacement |
|
71 | - * @param string $string |
|
72 | 62 | * @return string |
73 | 63 | */ |
74 | 64 | function regReplace() { |
@@ -131,8 +121,6 @@ discard block |
||
131 | 121 | * ``` |
132 | 122 | * |
133 | 123 | * @signature String -> String -> String |
134 | - * @param string $delimiter |
|
135 | - * @param string $string |
|
136 | 124 | * @return string |
137 | 125 | */ |
138 | 126 | function snakeCase() { |
@@ -158,8 +146,6 @@ discard block |
||
158 | 146 | * ``` |
159 | 147 | * |
160 | 148 | * @signature String -> String -> Boolean |
161 | - * @param string $token |
|
162 | - * @param string $string |
|
163 | 149 | * @return bool |
164 | 150 | */ |
165 | 151 | function startsWith() { |
@@ -181,8 +167,6 @@ discard block |
||
181 | 167 | * ``` |
182 | 168 | * |
183 | 169 | * @signature String -> String -> Boolean |
184 | - * @param string $token |
|
185 | - * @param string $string |
|
186 | 170 | * @return bool |
187 | 171 | */ |
188 | 172 | function endsWith() { |
@@ -204,8 +188,6 @@ discard block |
||
204 | 188 | * ``` |
205 | 189 | * |
206 | 190 | * @signature String -> String -> Boolean |
207 | - * @param string $pattern |
|
208 | - * @param string $string |
|
209 | 191 | * @return bool |
210 | 192 | */ |
211 | 193 | function test() { |
@@ -225,8 +207,6 @@ discard block |
||
225 | 207 | * ``` |
226 | 208 | * |
227 | 209 | * @signature String -> String -> [String] |
228 | - * @param string $pattern |
|
229 | - * @param string $string |
|
230 | 210 | * @return array |
231 | 211 | */ |
232 | 212 | function match() { |
@@ -247,8 +227,6 @@ discard block |
||
247 | 227 | * ``` |
248 | 228 | * |
249 | 229 | * @signature String -> String -> Number |
250 | - * @param string $token |
|
251 | - * @param string $text |
|
252 | 230 | * @return int |
253 | 231 | */ |
254 | 232 | function occurences() { |
@@ -271,9 +249,6 @@ discard block |
||
271 | 249 | * ``` |
272 | 250 | * |
273 | 251 | * @signature String -> String -> String -> [String] |
274 | - * @param string $surrounders |
|
275 | - * @param string $separator |
|
276 | - * @param sring $text |
|
277 | 252 | * @return array |
278 | 253 | */ |
279 | 254 | function chunks() { |
@@ -32,7 +32,7 @@ discard block |
||
32 | 32 | * @return string |
33 | 33 | */ |
34 | 34 | function join() { |
35 | - return apply(curry(function($glue, $pieces){ |
|
35 | + return apply(curry(function($glue, $pieces) { |
|
36 | 36 | return implode($glue, $pieces); |
37 | 37 | }), func_get_args()); |
38 | 38 | } |
@@ -285,8 +285,7 @@ discard block |
||
285 | 285 | $count = occurences(__(), $item); |
286 | 286 | $counts = map(function($index) use ($result, $count) { |
287 | 287 | return ($result->openings[$index] == $result->closings[$index]) ? |
288 | - ($result->counts[$index] + $count($result->openings[$index])) % 2 : |
|
289 | - $result->counts[$index] + $count($result->openings[$index]) - $count($result->closings[$index]); |
|
288 | + ($result->counts[$index] + $count($result->openings[$index])) % 2 : $result->counts[$index] + $count($result->openings[$index]) - $count($result->closings[$index]); |
|
290 | 289 | }, range(0, length($result->counts) - 1)); |
291 | 290 | if (0 == $result->total) { |
292 | 291 | return (object) [ |
@@ -311,7 +310,7 @@ discard block |
||
311 | 310 | 'counts' => array_fill(0, length($surrounders), 0), |
312 | 311 | 'total' => 0 |
313 | 312 | ]) |
314 | - ->then(function($data){ |
|
313 | + ->then(function($data) { |
|
315 | 314 | return $data->items; |
316 | 315 | }) |
317 | 316 | ->get(); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | * @return mixed |
22 | 22 | */ |
23 | 23 | function value() { |
24 | - $value = function($name, $array){ |
|
24 | + $value = function($name, $array) { |
|
25 | 25 | return $array[$name]; |
26 | 26 | }; |
27 | 27 | return apply(curry($value), func_get_args()); |
@@ -40,7 +40,7 @@ discard block |
||
40 | 40 | * @return array |
41 | 41 | */ |
42 | 42 | function map() { |
43 | - return apply(curry(function($fn, $array){ |
|
43 | + return apply(curry(function($fn, $array) { |
|
44 | 44 | return array_map($fn, $array); |
45 | 45 | }), func_get_args()); |
46 | 46 | } |
@@ -59,7 +59,7 @@ discard block |
||
59 | 59 | * @return array |
60 | 60 | */ |
61 | 61 | function filter() { |
62 | - $filter = function($fn, $array){ |
|
62 | + $filter = function($fn, $array) { |
|
63 | 63 | return array_values(array_filter($array, $fn)); |
64 | 64 | }; |
65 | 65 | return apply(curry($filter), func_get_args()); |
@@ -81,7 +81,7 @@ discard block |
||
81 | 81 | * @return array |
82 | 82 | */ |
83 | 83 | function reduce() { |
84 | - $reduce = function($fn, $initial, $array){ |
|
84 | + $reduce = function($fn, $initial, $array) { |
|
85 | 85 | return array_reduce($array, $fn, $initial); |
86 | 86 | }; |
87 | 87 | return apply(curry($reduce), func_get_args()); |
@@ -107,7 +107,7 @@ discard block |
||
107 | 107 | * @return array |
108 | 108 | */ |
109 | 109 | function each() { |
110 | - $each = function($fn, $array){ |
|
110 | + $each = function($fn, $array) { |
|
111 | 111 | foreach ($array as $item) { |
112 | 112 | apply($fn, [$item]); |
113 | 113 | } |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | * @return mixed |
132 | 132 | */ |
133 | 133 | function head($array) { |
134 | - if(is_string($array)) |
|
134 | + if (is_string($array)) |
|
135 | 135 | return substr($array, 0, 1); |
136 | 136 | return (count($array) > 0) |
137 | 137 | ? $array[0] |
@@ -153,7 +153,7 @@ discard block |
||
153 | 153 | * @return mixed |
154 | 154 | */ |
155 | 155 | function last($array) { |
156 | - if(is_string($array)) |
|
156 | + if (is_string($array)) |
|
157 | 157 | return substr($array, -1); |
158 | 158 | return (count($array) > 0) |
159 | 159 | ? $array[count($array) - 1] |
@@ -176,7 +176,7 @@ discard block |
||
176 | 176 | * @return array |
177 | 177 | */ |
178 | 178 | function init($array) { |
179 | - if(is_string($array)) |
|
179 | + if (is_string($array)) |
|
180 | 180 | return (strlen($array) > 1) |
181 | 181 | ? substr($array, 0, strlen($array) - 1) |
182 | 182 | : ''; |
@@ -201,7 +201,7 @@ discard block |
||
201 | 201 | * @return array |
202 | 202 | */ |
203 | 203 | function tail($array) { |
204 | - if(is_string($array)) |
|
204 | + if (is_string($array)) |
|
205 | 205 | return (strlen($array) > 1) |
206 | 206 | ? substr($array, 1) |
207 | 207 | : ''; |
@@ -323,7 +323,7 @@ discard block |
||
323 | 323 | * @return array |
324 | 324 | */ |
325 | 325 | function append() { |
326 | - $append = function ($item, $array) { |
|
326 | + $append = function($item, $array) { |
|
327 | 327 | if (is_string($array)) |
328 | 328 | return $array . $item; |
329 | 329 | return array_merge($array, [$item]); |
@@ -345,7 +345,7 @@ discard block |
||
345 | 345 | * @return array |
346 | 346 | */ |
347 | 347 | function prepend() { |
348 | - $prepend = function ($item, $array) { |
|
348 | + $prepend = function($item, $array) { |
|
349 | 349 | if (is_string($array)) |
350 | 350 | return $item . $array; |
351 | 351 | return array_merge([$item], $array); |
@@ -373,7 +373,7 @@ discard block |
||
373 | 373 | */ |
374 | 374 | function take() { |
375 | 375 | $take = function($count, $array) { |
376 | - if(is_string($array)) { |
|
376 | + if (is_string($array)) { |
|
377 | 377 | return ($count >= 0) |
378 | 378 | ? substr($array, 0, $count) |
379 | 379 | : substr($array, $count); |
@@ -406,7 +406,7 @@ discard block |
||
406 | 406 | */ |
407 | 407 | function remove($count, $array) { |
408 | 408 | $remove = function($count, $array) { |
409 | - if(is_string($array)) { |
|
409 | + if (is_string($array)) { |
|
410 | 410 | return ($count >= 0) |
411 | 411 | ? substr($array, $count) |
412 | 412 | : substr($array, 0, $count); |
@@ -474,9 +474,9 @@ discard block |
||
474 | 474 | */ |
475 | 475 | function slices() { |
476 | 476 | $slices = function($size, $array) { |
477 | - if(empty($array)) |
|
477 | + if (empty($array)) |
|
478 | 478 | return is_string($array) ? '' : []; |
479 | - if(length($array) <= $size) |
|
479 | + if (length($array) <= $size) |
|
480 | 480 | return [$array]; |
481 | 481 | return prepend(take($size, $array), slices($size, remove($size, $array))); |
482 | 482 | }; |
@@ -500,7 +500,7 @@ discard block |
||
500 | 500 | */ |
501 | 501 | function contains() { |
502 | 502 | $contains = function($item, $array) { |
503 | - if(is_string($array)) |
|
503 | + if (is_string($array)) |
|
504 | 504 | return false !== strpos($array, $item); |
505 | 505 | return in_array($item, $array); |
506 | 506 | }; |
@@ -131,8 +131,9 @@ discard block |
||
131 | 131 | * @return mixed |
132 | 132 | */ |
133 | 133 | function head($array) { |
134 | - if(is_string($array)) |
|
135 | - return substr($array, 0, 1); |
|
134 | + if(is_string($array)) { |
|
135 | + return substr($array, 0, 1); |
|
136 | + } |
|
136 | 137 | return (count($array) > 0) |
137 | 138 | ? $array[0] |
138 | 139 | : null; |
@@ -153,8 +154,9 @@ discard block |
||
153 | 154 | * @return mixed |
154 | 155 | */ |
155 | 156 | function last($array) { |
156 | - if(is_string($array)) |
|
157 | - return substr($array, -1); |
|
157 | + if(is_string($array)) { |
|
158 | + return substr($array, -1); |
|
159 | + } |
|
158 | 160 | return (count($array) > 0) |
159 | 161 | ? $array[count($array) - 1] |
160 | 162 | : null; |
@@ -176,10 +178,11 @@ discard block |
||
176 | 178 | * @return array |
177 | 179 | */ |
178 | 180 | function init($array) { |
179 | - if(is_string($array)) |
|
180 | - return (strlen($array) > 1) |
|
181 | + if(is_string($array)) { |
|
182 | + return (strlen($array) > 1) |
|
181 | 183 | ? substr($array, 0, strlen($array) - 1) |
182 | 184 | : ''; |
185 | + } |
|
183 | 186 | return (count($array) > 1) |
184 | 187 | ? array_slice($array, 0, count($array) - 1) |
185 | 188 | : []; |
@@ -201,10 +204,11 @@ discard block |
||
201 | 204 | * @return array |
202 | 205 | */ |
203 | 206 | function tail($array) { |
204 | - if(is_string($array)) |
|
205 | - return (strlen($array) > 1) |
|
207 | + if(is_string($array)) { |
|
208 | + return (strlen($array) > 1) |
|
206 | 209 | ? substr($array, 1) |
207 | 210 | : ''; |
211 | + } |
|
208 | 212 | return (count($array) > 1) |
209 | 213 | ? array_slice($array, 1) |
210 | 214 | : []; |
@@ -302,8 +306,9 @@ discard block |
||
302 | 306 | */ |
303 | 307 | function concat() { |
304 | 308 | $concat = function($array1, $array2) { |
305 | - if (is_string($array1)) |
|
306 | - return $array1 . $array2; |
|
309 | + if (is_string($array1)) { |
|
310 | + return $array1 . $array2; |
|
311 | + } |
|
307 | 312 | return array_merge($array1, $array2); |
308 | 313 | }; |
309 | 314 | return apply(curry($concat), func_get_args()); |
@@ -324,8 +329,9 @@ discard block |
||
324 | 329 | */ |
325 | 330 | function append() { |
326 | 331 | $append = function ($item, $array) { |
327 | - if (is_string($array)) |
|
328 | - return $array . $item; |
|
332 | + if (is_string($array)) { |
|
333 | + return $array . $item; |
|
334 | + } |
|
329 | 335 | return array_merge($array, [$item]); |
330 | 336 | }; |
331 | 337 | return apply(curry($append), func_get_args()); |
@@ -346,8 +352,9 @@ discard block |
||
346 | 352 | */ |
347 | 353 | function prepend() { |
348 | 354 | $prepend = function ($item, $array) { |
349 | - if (is_string($array)) |
|
350 | - return $item . $array; |
|
355 | + if (is_string($array)) { |
|
356 | + return $item . $array; |
|
357 | + } |
|
351 | 358 | return array_merge([$item], $array); |
352 | 359 | }; |
353 | 360 | return apply(curry($prepend), func_get_args()); |
@@ -474,10 +481,12 @@ discard block |
||
474 | 481 | */ |
475 | 482 | function slices() { |
476 | 483 | $slices = function($size, $array) { |
477 | - if(empty($array)) |
|
478 | - return is_string($array) ? '' : []; |
|
479 | - if(length($array) <= $size) |
|
480 | - return [$array]; |
|
484 | + if(empty($array)) { |
|
485 | + return is_string($array) ? '' : []; |
|
486 | + } |
|
487 | + if(length($array) <= $size) { |
|
488 | + return [$array]; |
|
489 | + } |
|
481 | 490 | return prepend(take($size, $array), slices($size, remove($size, $array))); |
482 | 491 | }; |
483 | 492 | return apply(curry($slices), func_get_args()); |
@@ -500,8 +509,9 @@ discard block |
||
500 | 509 | */ |
501 | 510 | function contains() { |
502 | 511 | $contains = function($item, $array) { |
503 | - if(is_string($array)) |
|
504 | - return false !== strpos($array, $item); |
|
512 | + if(is_string($array)) { |
|
513 | + return false !== strpos($array, $item); |
|
514 | + } |
|
505 | 515 | return in_array($item, $array); |
506 | 516 | }; |
507 | 517 | return apply(curry($contains), func_get_args()); |
@@ -16,8 +16,6 @@ discard block |
||
16 | 16 | * ``` |
17 | 17 | * |
18 | 18 | * @signature String -> [key => *] -> * |
19 | - * @param string $name |
|
20 | - * @param array $array |
|
21 | 19 | * @return mixed |
22 | 20 | */ |
23 | 21 | function value() { |
@@ -35,8 +33,6 @@ discard block |
||
35 | 33 | * ``` |
36 | 34 | * |
37 | 35 | * @signature (a -> b) -> [a] -> [b] |
38 | - * @param callable $fn |
|
39 | - * @param array $array |
|
40 | 36 | * @return array |
41 | 37 | */ |
42 | 38 | function map() { |
@@ -54,8 +50,6 @@ discard block |
||
54 | 50 | * $numeric($array) // [1, 3] |
55 | 51 | * ``` |
56 | 52 | * @signature (a -> Boolean) -> [a] -> [a] |
57 | - * @param callable $fn |
|
58 | - * @param array $array |
|
59 | 53 | * @return array |
60 | 54 | */ |
61 | 55 | function filter() { |
@@ -75,9 +69,6 @@ discard block |
||
75 | 69 | * ``` |
76 | 70 | * |
77 | 71 | * @signature (* -> a -> *) -> * -> [a] -> * |
78 | - * @param callable $fn |
|
79 | - * @param mixed $initial |
|
80 | - * @param array $array |
|
81 | 72 | * @return array |
82 | 73 | */ |
83 | 74 | function reduce() { |
@@ -102,8 +93,6 @@ discard block |
||
102 | 93 | * ``` |
103 | 94 | * |
104 | 95 | * @signature (a -> *) -> [a] -> [a] |
105 | - * @param callable $fn |
|
106 | - * @param array $array |
|
107 | 96 | * @return array |
108 | 97 | */ |
109 | 98 | function each() { |
@@ -255,8 +244,6 @@ discard block |
||
255 | 244 | * ``` |
256 | 245 | * |
257 | 246 | * @signature (a -> Boolean) -> [a] -> Boolean |
258 | - * @param callable $predicate |
|
259 | - * @param array $array |
|
260 | 247 | * @return bool |
261 | 248 | */ |
262 | 249 | function all() { |
@@ -276,8 +263,6 @@ discard block |
||
276 | 263 | * ``` |
277 | 264 | * |
278 | 265 | * @signature (a -> Boolean) -> [a] -> Boolean |
279 | - * @param callable $predicate |
|
280 | - * @param array $array |
|
281 | 266 | * @return bool |
282 | 267 | */ |
283 | 268 | function any() { |
@@ -296,8 +281,6 @@ discard block |
||
296 | 281 | * ``` |
297 | 282 | * |
298 | 283 | * @signature [*] -> [*] -> [*] |
299 | - * @param array $array1 |
|
300 | - * @param array $array2 |
|
301 | 284 | * @return array |
302 | 285 | */ |
303 | 286 | function concat() { |
@@ -318,8 +301,6 @@ discard block |
||
318 | 301 | * |
319 | 302 | * @signature * -> [*] -> [*] |
320 | 303 | * @signature String -> String -> String |
321 | - * @param mixed $item |
|
322 | - * @param array $array |
|
323 | 304 | * @return array |
324 | 305 | */ |
325 | 306 | function append() { |
@@ -340,8 +321,6 @@ discard block |
||
340 | 321 | * |
341 | 322 | * @signature * -> [*] -> [*] |
342 | 323 | * @signature String -> String -> String |
343 | - * @param mixed $item |
|
344 | - * @param array $array |
|
345 | 324 | * @return array |
346 | 325 | */ |
347 | 326 | function prepend() { |
@@ -367,8 +346,6 @@ discard block |
||
367 | 346 | * |
368 | 347 | * @signature Number -> [a] -> [a] |
369 | 348 | * @signature Number -> String -> String |
370 | - * @param int $count |
|
371 | - * @param array $array |
|
372 | 349 | * @return array |
373 | 350 | */ |
374 | 351 | function take() { |
@@ -400,8 +377,6 @@ discard block |
||
400 | 377 | * |
401 | 378 | * @signature Number -> [a] -> [a] |
402 | 379 | * @signature Number -> String -> String |
403 | - * @param int $count |
|
404 | - * @param array $array |
|
405 | 380 | * @return array |
406 | 381 | */ |
407 | 382 | function remove() { |
@@ -444,8 +419,6 @@ discard block |
||
444 | 419 | * ``` |
445 | 420 | * |
446 | 421 | * @signature (a -> [b]) -> [a] -> [b] |
447 | - * @param callable $fn |
|
448 | - * @param array $array |
|
449 | 422 | * @return array |
450 | 423 | */ |
451 | 424 | function chain() { |
@@ -468,8 +441,6 @@ discard block |
||
468 | 441 | * |
469 | 442 | * @signature Number -> [a] -> [[a]] |
470 | 443 | * @signature Number -> String -> [String] |
471 | - * @param int $size |
|
472 | - * @param array $array |
|
473 | 444 | * @return array |
474 | 445 | */ |
475 | 446 | function slices() { |
@@ -494,8 +465,6 @@ discard block |
||
494 | 465 | * |
495 | 466 | * @signature a -> [a] -> Boolean |
496 | 467 | * @signature String -> String -> Boolean |
497 | - * @param mixed $item |
|
498 | - * @param array|string $array |
|
499 | 468 | * @return bool |
500 | 469 | */ |
501 | 470 | function contains() { |
@@ -24,7 +24,7 @@ discard block |
||
24 | 24 | * @param Error|null $error |
25 | 25 | * @return Error |
26 | 26 | */ |
27 | - public static function of ($message, Error $error = null) |
|
27 | + public static function of($message, Error $error = null) |
|
28 | 28 | { |
29 | 29 | return new Error($message, $error); |
30 | 30 | } |
@@ -35,7 +35,7 @@ discard block |
||
35 | 35 | * @param string $message |
36 | 36 | * @param Error|null $error |
37 | 37 | */ |
38 | - protected function __construct ($message, Error $error = null) |
|
38 | + protected function __construct($message, Error $error = null) |
|
39 | 39 | { |
40 | 40 | if (null != $error) |
41 | 41 | $message = $error->message() . ' -> ' . $message; |
@@ -52,7 +52,7 @@ discard block |
||
52 | 52 | * @signature Error -> String |
53 | 53 | * @return string |
54 | 54 | */ |
55 | - public function message () |
|
55 | + public function message() |
|
56 | 56 | { |
57 | 57 | return $this->message; |
58 | 58 | } |
@@ -37,8 +37,9 @@ |
||
37 | 37 | */ |
38 | 38 | protected function __construct ($message, Error $error = null) |
39 | 39 | { |
40 | - if (null != $error) |
|
41 | - $message = $error->message() . ' -> ' . $message; |
|
40 | + if (null != $error) { |
|
41 | + $message = $error->message() . ' -> ' . $message; |
|
42 | + } |
|
42 | 43 | $this->message = $message; |
43 | 44 | } |
44 | 45 |
@@ -71,7 +71,7 @@ discard block |
||
71 | 71 | * @param mixed $something |
72 | 72 | * @return string |
73 | 73 | */ |
74 | -function toString ($something) { |
|
74 | +function toString($something) { |
|
75 | 75 | switch (type($something)) { |
76 | 76 | case 'String': |
77 | 77 | return $something; |
@@ -90,8 +90,8 @@ discard block |
||
90 | 90 | break; |
91 | 91 | case 'ArrayObject': |
92 | 92 | case 'Array': |
93 | - return '[' . join(', ', map(function($pair){ |
|
94 | - return $pair[0].' => '. toString($pair[1]); |
|
93 | + return '[' . join(', ', map(function($pair) { |
|
94 | + return $pair[0] . ' => ' . toString($pair[1]); |
|
95 | 95 | }, toPairs($something))) . ']'; |
96 | 96 | break; |
97 | 97 | case 'Error': |
@@ -100,7 +100,7 @@ discard block |
||
100 | 100 | return is_callable([$something, '__toString']) ? $something->__toString() : '[Object]'; |
101 | 101 | break; |
102 | 102 | default: |
103 | - return '['.type($something).']'; |
|
103 | + return '[' . type($something) . ']'; |
|
104 | 104 | } |
105 | 105 | } |
106 | 106 |
@@ -27,22 +27,42 @@ |
||
27 | 27 | * @return string |
28 | 28 | */ |
29 | 29 | function type($data) { |
30 | - if (null === $data) return 'Null'; |
|
31 | - if (true === $data || false === $data) return 'Boolean'; |
|
32 | - if ($data instanceof Error) return 'Error'; |
|
33 | - if ($data instanceof Stream) return 'Stream'; |
|
34 | - if (is_callable($data)) return 'Function'; |
|
35 | - if (is_resource($data)) return 'Resource'; |
|
36 | - if (is_string($data)) return 'String'; |
|
37 | - if (is_integer($data) || is_float($data)) return 'Number'; |
|
30 | + if (null === $data) { |
|
31 | + return 'Null'; |
|
32 | + } |
|
33 | + if (true === $data || false === $data) { |
|
34 | + return 'Boolean'; |
|
35 | + } |
|
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 | + } |
|
45 | + if (is_resource($data)) { |
|
46 | + return 'Resource'; |
|
47 | + } |
|
48 | + if (is_string($data)) { |
|
49 | + return 'String'; |
|
50 | + } |
|
51 | + if (is_integer($data) || is_float($data)) { |
|
52 | + return 'Number'; |
|
53 | + } |
|
38 | 54 | if (is_array($data)) { |
39 | - if (all('is_numeric', array_keys($data))) |
|
40 | - return 'List'; |
|
41 | - if (all('is_string', array_keys($data))) |
|
42 | - return 'ArrayObject'; |
|
55 | + if (all('is_numeric', array_keys($data))) { |
|
56 | + return 'List'; |
|
57 | + } |
|
58 | + if (all('is_string', array_keys($data))) { |
|
59 | + return 'ArrayObject'; |
|
60 | + } |
|
43 | 61 | return 'Array'; |
44 | 62 | } |
45 | - if (is_object($data)) return 'Object'; |
|
63 | + if (is_object($data)) { |
|
64 | + return 'Object'; |
|
65 | + } |
|
46 | 66 | return 'Unknown'; |
47 | 67 | } |
48 | 68 |
@@ -17,7 +17,7 @@ discard block |
||
17 | 17 | // Reads the list of sources files from 'composer.json' |
18 | 18 | // * -> IO [String] |
19 | 19 | function modules() { |
20 | - $composer = json_decode(file_get_contents(__DIR__.'/composer.json')); |
|
20 | + $composer = json_decode(file_get_contents(__DIR__ . '/composer.json')); |
|
21 | 21 | return $composer->autoload->files; |
22 | 22 | } |
23 | 23 | |
@@ -39,7 +39,7 @@ discard block |
||
39 | 39 | * @field type String |
40 | 40 | */ |
41 | 41 | function argsOf($data) { |
42 | - return F\map(function($tag){ |
|
42 | + return F\map(function($tag) { |
|
43 | 43 | return (object) [ |
44 | 44 | 'type' => $tag->name, |
45 | 45 | 'name' => $tag->description |
@@ -50,7 +50,7 @@ discard block |
||
50 | 50 | // Extracts signatures of a function. |
51 | 51 | // Object -> [String] |
52 | 52 | function signaturesOf($data) { |
53 | - return F\map(function($tag){ |
|
53 | + return F\map(function($tag) { |
|
54 | 54 | return $tag->string; |
55 | 55 | }, tags('signature', $data)); |
56 | 56 | } |
@@ -124,7 +124,7 @@ discard block |
||
124 | 124 | // Get a markdown code block |
125 | 125 | // String -> String -> String |
126 | 126 | function code($lang, $text) { |
127 | - if(trim($text) == '') |
|
127 | + if (trim($text) == '') |
|
128 | 128 | return ''; |
129 | 129 | return "```{$lang}\n{$text}\n```"; |
130 | 130 | } |
@@ -138,7 +138,7 @@ discard block |
||
138 | 138 | $args = F\map(function($arg) { |
139 | 139 | return $arg->type . ' ' . $arg->name; |
140 | 140 | }, $fn->args); |
141 | - $proto = $fn->name . '('. F\join(', ', $args) .') : ' . $fn->return; |
|
141 | + $proto = $fn->name . '(' . F\join(', ', $args) . ') : ' . $fn->return; |
|
142 | 142 | return F\join("\n\n", [ |
143 | 143 | "## {$fn->name}", |
144 | 144 | code('php', $proto), |
@@ -153,11 +153,11 @@ discard block |
||
153 | 153 | function addContents() { |
154 | 154 | $addContents = function($name, $parts) { |
155 | 155 | $names = F\filter(F\notEq($name), F\map(F\value('name'), $parts)); |
156 | - $contents = F\map(function ($partname) use($name) { |
|
156 | + $contents = F\map(function($partname) use($name) { |
|
157 | 157 | $link = URL . "/docs/{$name}.md#{$partname}"; |
158 | 158 | return "- [{$partname}]($link)"; |
159 | 159 | }, $names); |
160 | - file_put_contents ("docs/README.md", |
|
160 | + file_put_contents("docs/README.md", |
|
161 | 161 | F\join("\n\n", F\concat(["## {$name}"], $contents)) . "\n\n" |
162 | 162 | , FILE_APPEND); |
163 | 163 | return array_merge(['# ' . $name, '## Table Of Contents'], $contents, F\map(F\value('md'), $parts)); |
@@ -169,10 +169,10 @@ discard block |
||
169 | 169 | function generateModule($file) { |
170 | 170 | $content = F\pipe( |
171 | 171 | F\map('Demo\\block'), |
172 | - F\filter(function($block){ |
|
172 | + F\filter(function($block) { |
|
173 | 173 | return $block->type == 'function' && !$block->is_internal; |
174 | 174 | }), |
175 | - F\map(function($block){ |
|
175 | + F\map(function($block) { |
|
176 | 176 | return [ |
177 | 177 | 'name' => $block->name, |
178 | 178 | 'md' => markdown($block) |
@@ -182,7 +182,7 @@ discard block |
||
182 | 182 | F\join("\n\n") |
183 | 183 | ); |
184 | 184 | |
185 | - file_put_contents ( |
|
185 | + file_put_contents( |
|
186 | 186 | F\replace(['src', '.php'], ['docs', '.md'], $file), |
187 | 187 | $content(json_decode(shell_exec("dox -r < {$file}"))) |
188 | 188 | ); |
@@ -193,7 +193,7 @@ discard block |
||
193 | 193 | function generateClass($name) { |
194 | 194 | $content = F\pipe( |
195 | 195 | F\map('Demo\\block'), |
196 | - F\filter(function($block){ |
|
196 | + F\filter(function($block) { |
|
197 | 197 | return in_array($block->type, ['method', 'class']) && !$block->is_internal; |
198 | 198 | }), |
199 | 199 | f\map(function($block) use ($name) { |
@@ -202,7 +202,7 @@ discard block |
||
202 | 202 | } |
203 | 203 | return $block; |
204 | 204 | }), |
205 | - F\map(function($block){ |
|
205 | + F\map(function($block) { |
|
206 | 206 | return [ |
207 | 207 | 'name' => $block->name, |
208 | 208 | 'md' => markdown($block) |
@@ -212,7 +212,7 @@ discard block |
||
212 | 212 | F\join("\n\n") |
213 | 213 | ); |
214 | 214 | |
215 | - file_put_contents ( |
|
215 | + file_put_contents( |
|
216 | 216 | "docs/{$name}.md", |
217 | 217 | $content(json_decode(shell_exec("dox -r < src/{$name}.php"))) |
218 | 218 | ); |
@@ -220,7 +220,7 @@ discard block |
||
220 | 220 | |
221 | 221 | // The entry point |
222 | 222 | file_put_contents('docs/README.md', "# Reference Documentation \n\n"); |
223 | -file_put_contents ("docs/README.md", "# Function Modules\n\n" , FILE_APPEND); |
|
223 | +file_put_contents("docs/README.md", "# Function Modules\n\n", FILE_APPEND); |
|
224 | 224 | F\each('Demo\\generateModule', modules()); |
225 | -file_put_contents ("docs/README.md", "# Containers\n\n" , FILE_APPEND); |
|
225 | +file_put_contents("docs/README.md", "# Containers\n\n", FILE_APPEND); |
|
226 | 226 | F\each('Demo\\generateClass', ['Stream', 'Error']); |
@@ -67,13 +67,16 @@ discard block |
||
67 | 67 | // Extracts the type of a block |
68 | 68 | // Object -> String |
69 | 69 | function typeOf($data) { |
70 | - if (isset($data->ctx->type)) |
|
71 | - return $data->ctx->type; |
|
72 | - if (F\length(tags('var', $data)) > 0) |
|
73 | - return 'attr'; |
|
74 | - if (F\length(tags('return', $data)) > 0) |
|
75 | - return 'method'; |
|
76 | -} |
|
70 | + if (isset($data->ctx->type)) { |
|
71 | + return $data->ctx->type; |
|
72 | + } |
|
73 | + if (F\length(tags('var', $data)) > 0) { |
|
74 | + return 'attr'; |
|
75 | + } |
|
76 | + if (F\length(tags('return', $data)) > 0) { |
|
77 | + return 'method'; |
|
78 | + } |
|
79 | + } |
|
77 | 80 | |
78 | 81 | // Extract keywords |
79 | 82 | // Object -> [String] |
@@ -82,8 +85,9 @@ discard block |
||
82 | 85 | return []; |
83 | 86 | } |
84 | 87 | $size = strpos($data->code, '('); |
85 | - if ($size === false) |
|
86 | - $size = strlen($data->code); |
|
88 | + if ($size === false) { |
|
89 | + $size = strlen($data->code); |
|
90 | + } |
|
87 | 91 | $keywords = F\pipe( |
88 | 92 | F\take($size), |
89 | 93 | F\split(' '), |
@@ -124,8 +128,9 @@ discard block |
||
124 | 128 | // Get a markdown code block |
125 | 129 | // String -> String -> String |
126 | 130 | function code($lang, $text) { |
127 | - if(trim($text) == '') |
|
128 | - return ''; |
|
131 | + if(trim($text) == '') { |
|
132 | + return ''; |
|
133 | + } |
|
129 | 134 | return "```{$lang}\n{$text}\n```"; |
130 | 135 | } |
131 | 136 |