Completed
Push — master ( 713d54...d55531 )
by Amine
02:08
created
src/functions.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -91,8 +91,9 @@
 block discarded – undo
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) {
Please login to merge, or discard this patch.
src/Error.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -37,8 +37,9 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/Stream.php 1 patch
Braces   +18 added lines, -12 removed lines patch added patch discarded remove patch
@@ -84,8 +84,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
     }
Please login to merge, or discard this patch.
src/common.php 1 patch
Braces   +33 added lines, -13 removed lines patch added patch discarded remove patch
@@ -27,22 +27,42 @@
 block discarded – undo
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
 
Please login to merge, or discard this patch.
generate-docs.php 1 patch
Braces   +16 added lines, -11 removed lines patch added patch discarded remove patch
@@ -67,13 +67,16 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
src/object.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -32,8 +32,9 @@
 block discarded – undo
32 32
  */
33 33
 function attributes() {
34 34
     $attrs = function($object) {
35
-        if (is_object($object))
36
-            return get_object_vars($object);
35
+        if (is_object($object)) {
36
+                    return get_object_vars($object);
37
+        }
37 38
         return $object;
38 39
     };
39 40
     return apply(curry($attrs), func_get_args());
Please login to merge, or discard this patch.
src/list.php 1 patch
Braces   +39 added lines, -26 removed lines patch added patch discarded remove patch
@@ -128,8 +128,9 @@  discard block
 block discarded – undo
128 128
  * @return mixed
129 129
  */
130 130
 function head($list) {
131
-    if(is_string($list))
132
-        return substr($list, 0, 1);
131
+    if(is_string($list)) {
132
+            return substr($list, 0, 1);
133
+    }
133 134
     return (count($list) > 0)
134 135
         ? $list[0]
135 136
         : null;
@@ -150,8 +151,9 @@  discard block
 block discarded – undo
150 151
  * @return mixed
151 152
  */
152 153
 function last($list) {
153
-    if(is_string($list))
154
-        return substr($list, -1);
154
+    if(is_string($list)) {
155
+            return substr($list, -1);
156
+    }
155 157
     return (count($list) > 0)
156 158
         ? $list[count($list) - 1]
157 159
         : null;
@@ -173,10 +175,11 @@  discard block
 block discarded – undo
173 175
  * @return array
174 176
  */
175 177
 function init($list) {
176
-    if(is_string($list))
177
-        return (strlen($list) > 1)
178
+    if(is_string($list)) {
179
+            return (strlen($list) > 1)
178 180
             ? substr($list, 0, strlen($list) - 1)
179 181
             : '';
182
+    }
180 183
     return (count($list) > 1)
181 184
         ? array_slice($list, 0, count($list) - 1)
182 185
         : [];
@@ -198,10 +201,11 @@  discard block
 block discarded – undo
198 201
  * @return array
199 202
  */
200 203
 function tail($list) {
201
-    if(is_string($list))
202
-        return (strlen($list) > 1)
204
+    if(is_string($list)) {
205
+            return (strlen($list) > 1)
203 206
             ? substr($list, 1)
204 207
             : '';
208
+    }
205 209
     return (count($list) > 1)
206 210
         ? array_slice($list, 1)
207 211
         : [];
@@ -299,8 +303,9 @@  discard block
 block discarded – undo
299 303
  */
300 304
 function concat() {
301 305
     $concat = function($list1, $list2) {
302
-        if (is_string($list1))
303
-            return $list1 . $list2;
306
+        if (is_string($list1)) {
307
+                    return $list1 . $list2;
308
+        }
304 309
         return array_merge($list1, $list2);
305 310
     };
306 311
     return apply(curry($concat), func_get_args());
@@ -372,8 +377,9 @@  discard block
 block discarded – undo
372 377
  */
373 378
 function insertAll() {
374 379
     $insertAll = function($position, $items, $list) {
375
-        if ($position < 0)
376
-            $position = length($list) - $position;
380
+        if ($position < 0) {
381
+                    $position = length($list) - $position;
382
+        }
377 383
         return concatAll([take($position, $list), $items, remove($position, $list)]);
378 384
     };
379 385
     return apply(curry($insertAll), func_get_args());
@@ -437,8 +443,9 @@  discard block
 block discarded – undo
437 443
  */
438 444
 function take() {
439 445
     $take = function($count, $list) {
440
-        if ($count > $length || $count < -$length)
441
-            return [];
446
+        if ($count > $length || $count < -$length) {
447
+                    return [];
448
+        }
442 449
         if(is_string($list)) {
443 450
             return ($count >= 0)
444 451
                 ? substr($list, 0, $count)
@@ -563,8 +570,9 @@  discard block
 block discarded – undo
563 570
 function remove() {
564 571
     $remove = function($count, $list) {
565 572
         $length = length($list);
566
-        if ($count > $length || $count < -$length)
567
-            return [];
573
+        if ($count > $length || $count < -$length) {
574
+                    return [];
575
+        }
568 576
         return ($count > 0) 
569 577
             ? take($count - $length)
570 578
             : take($count + $length);
@@ -695,10 +703,12 @@  discard block
 block discarded – undo
695 703
  */
696 704
 function slices() {
697 705
     $slices = function($size, $list) {
698
-        if(empty($list))
699
-            return is_string($list) ? '' : [];
700
-        if(length($list) <= $size)
701
-            return [$list];
706
+        if(empty($list)) {
707
+                    return is_string($list) ? '' : [];
708
+        }
709
+        if(length($list) <= $size) {
710
+                    return [$list];
711
+        }
702 712
         return prepend(take($size, $list), slices($size, remove($size, $list)));
703 713
     };
704 714
     return apply(curry($slices), func_get_args());
@@ -744,8 +754,9 @@  discard block
 block discarded – undo
744 754
 function findIndex() {
745 755
     $findIndex = function($predicate, $list) {
746 756
         foreach ($list as $key => $value) {
747
-            if ($predicate($value))
748
-                return $key;
757
+            if ($predicate($value)) {
758
+                            return $key;
759
+            }
749 760
         }
750 761
         return null;
751 762
     };
@@ -770,8 +781,9 @@  discard block
 block discarded – undo
770 781
 function findLastIndex() {
771 782
     $findLastIndex = function($predicate, $list) {
772 783
         foreach (reverse(toPairs($list)) as $pair) {
773
-            if($predicate($pair[1]))
774
-                return $pair[0];
784
+            if($predicate($pair[1])) {
785
+                            return $pair[0];
786
+            }
775 787
         }
776 788
         return null;
777 789
     };
@@ -959,8 +971,9 @@  discard block
 block discarded – undo
959 971
     $groupBy = function($fn, $list) {
960 972
         return reduce(function($result, $item) use($fn) {
961 973
             $index = $fn($item);
962
-            if (! isset($result[$index]))
963
-                $result[$index] = [];
974
+            if (! isset($result[$index])) {
975
+                            $result[$index] = [];
976
+            }
964 977
             $result[$index][] = $item;
965 978
             return $result;
966 979
         }, [], $list);
Please login to merge, or discard this patch.
src/operators.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -97,8 +97,9 @@
 block discarded – undo
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':
Please login to merge, or discard this patch.