Completed
Push — master ( 5e2d42...f80c85 )
by Amine
02:13
created
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/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.
src/Placeholder.php 1 patch
Braces   +3 added lines, -2 removed lines patch added patch discarded remove patch
@@ -11,8 +11,9 @@
 block discarded – undo
11 11
     private function __construct(){}
12 12
     public static function get()
13 13
     {
14
-        if(static::$instance === null)
15
-            static::$instance = new Placeholder;
14
+        if(static::$instance === null) {
15
+                    static::$instance = new Placeholder;
16
+        }
16 17
         return static::$instance;
17 18
     }
18 19
     public function __toString(){
Please login to merge, or discard this patch.
src/functions.php 1 patch
Braces   +9 added lines, -6 removed lines patch added patch discarded remove patch
@@ -59,8 +59,9 @@  discard block
 block discarded – undo
59 59
     $addArgument = function($currentBoundArgs, $arg) use($fnArgsCount) {
60 60
         $currentBoundArgsCount = count($currentBoundArgs);
61 61
         $placeholderPosition = 0;
62
-        while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition]))
63
-            $placeholderPosition ++;
62
+        while($placeholderPosition < $currentBoundArgsCount && !_is_placeholder($currentBoundArgs[$placeholderPosition])) {
63
+                    $placeholderPosition ++;
64
+        }
64 65
         if ($currentBoundArgsCount < $fnArgsCount || $placeholderPosition == $currentBoundArgsCount) {
65 66
             $currentBoundArgs[] = $arg;
66 67
         } else { // There is a placeholder and number of bound args > $fnArgsCount
@@ -87,8 +88,9 @@  discard block
 block discarded – undo
87 88
         $boundArgs = _merge_args($argsCount, $boundArgs, func_get_args());
88 89
         $numberOfPlaceholders = count(array_filter($boundArgs, _f('_is_placeholder')));
89 90
         $numberOfGivenArgs = count($boundArgs) - $numberOfPlaceholders;
90
-        if ($numberOfGivenArgs >= $argsCount)
91
-            return call_user_func_array($fn, $boundArgs);
91
+        if ($numberOfGivenArgs >= $argsCount) {
92
+                    return call_user_func_array($fn, $boundArgs);
93
+        }
92 94
         return _curried_function($fn, $argsCount, $boundArgs);
93 95
     };
94 96
 }
@@ -179,8 +181,9 @@  discard block
 block discarded – undo
179 181
  */
180 182
 function pipe() {
181 183
     $fns = func_get_args();
182
-    if(count($fns) < 1)
183
-        throw new InvalidArgument("pipe() requires at least one argument");
184
+    if(count($fns) < 1) {
185
+            throw new InvalidArgument("pipe() requires at least one argument");
186
+    }
184 187
     return curry(function () use ($fns) {
185 188
         $result = _apply(array_shift($fns), func_get_args());
186 189
         foreach ($fns as $fn) {
Please login to merge, or discard this patch.
src/list.php 1 patch
Braces   +42 added lines, -28 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
         : [];
@@ -302,8 +306,9 @@  discard block
 block discarded – undo
302 306
         $t1 = toString($list1);
303 307
         $t2 = toString($list2);
304 308
         // echo "Concating {$t1} and {$t2}", PHP_EOL;
305
-        if (is_string($list1) && is_string($list2))
306
-            return $list1 . $list2;
309
+        if (is_string($list1) && is_string($list2)) {
310
+                    return $list1 . $list2;
311
+        }
307 312
         return array_merge($list1, $list2);
308 313
     };
309 314
     return apply(curry($concat), func_get_args());
@@ -377,10 +382,12 @@  discard block
 block discarded – undo
377 382
 function insertAll() {
378 383
     $insertAll = function($position, $items, $list) {
379 384
         $length = length($list);
380
-        if ($position < 0)
381
-            $position = $length + $position;
382
-        if ($position < 0)
383
-            $position = 0;
385
+        if ($position < 0) {
386
+                    $position = $length + $position;
387
+        }
388
+        if ($position < 0) {
389
+                    $position = 0;
390
+        }
384 391
         return ($position >= $length)
385 392
             ? concat($list, $items)
386 393
             : concatAll([take($position, $list), $items, remove($position, $list)]);
@@ -447,8 +454,9 @@  discard block
 block discarded – undo
447 454
 function take() {
448 455
     $take = function($count, $list) {
449 456
         $length = length($list);
450
-        if ($count > $length || $count < -$length)
451
-            return [];
457
+        if ($count > $length || $count < -$length) {
458
+                    return [];
459
+        }
452 460
         if(is_string($list)) {
453 461
             return ($count >= 0)
454 462
                 ? substr($list, 0, $count)
@@ -573,8 +581,9 @@  discard block
 block discarded – undo
573 581
 function remove() {
574 582
     $remove = function($count, $list) {
575 583
         $length = length($list);
576
-        if ($count > $length || $count < -$length)
577
-            return [];
584
+        if ($count > $length || $count < -$length) {
585
+                    return [];
586
+        }
578 587
         return ($count > 0)
579 588
             ? take($count - $length, $list)
580 589
             : take($count + $length, $list);
@@ -705,10 +714,12 @@  discard block
 block discarded – undo
705 714
  */
706 715
 function slices() {
707 716
     $slices = function($size, $list) {
708
-        if(empty($list))
709
-            return is_string($list) ? '' : [];
710
-        if(length($list) <= $size)
711
-            return [$list];
717
+        if(empty($list)) {
718
+                    return is_string($list) ? '' : [];
719
+        }
720
+        if(length($list) <= $size) {
721
+                    return [$list];
722
+        }
712 723
         return prepend(take($size, $list), slices($size, remove($size, $list)));
713 724
     };
714 725
     return apply(curry($slices), func_get_args());
@@ -754,8 +765,9 @@  discard block
 block discarded – undo
754 765
 function findIndex() {
755 766
     $findIndex = function($predicate, $list) {
756 767
         foreach ($list as $key => $value) {
757
-            if ($predicate($value))
758
-                return $key;
768
+            if ($predicate($value)) {
769
+                            return $key;
770
+            }
759 771
         }
760 772
         return null;
761 773
     };
@@ -780,8 +792,9 @@  discard block
 block discarded – undo
780 792
 function findLastIndex() {
781 793
     $findLastIndex = function($predicate, $list) {
782 794
         foreach (reverse(toPairs($list)) as $pair) {
783
-            if($predicate($pair[1]))
784
-                return $pair[0];
795
+            if($predicate($pair[1])) {
796
+                            return $pair[0];
797
+            }
785 798
         }
786 799
         return null;
787 800
     };
@@ -972,8 +985,9 @@  discard block
 block discarded – undo
972 985
     $groupBy = function($fn, $list) {
973 986
         return reduce(function($result, $item) use($fn) {
974 987
             $index = $fn($item);
975
-            if (! isset($result[$index]))
976
-                $result[$index] = [];
988
+            if (! isset($result[$index])) {
989
+                            $result[$index] = [];
990
+            }
977 991
             $result[$index][] = $item;
978 992
             return $result;
979 993
         }, [], $list);
Please login to merge, or discard this patch.