Passed
Branch master (79af98)
by Roman
03:14
created
src/PeacefulBit/Packet/Nodes/FunctionNode.php 1 patch
Doc Comments   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -21,7 +21,7 @@
 block discarded – undo
21 21
     }
22 22
 
23 23
     /**
24
-     * @return string
24
+     * @return SymbolNode
25 25
      */
26 26
     public function getName()
27 27
     {
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Visitors/NodeCalculatorVisitor.php 2 patches
Doc Comments   +3 added lines patch added patch discarded remove patch
@@ -69,6 +69,9 @@
 block discarded – undo
69 69
         throw new \RuntimeException("Invalid function");
70 70
     }
71 71
 
72
+    /**
73
+     * @param Nodes\Node[] $args
74
+     */
72 75
     private function callLambdaNode(Nodes\LambdaNode $node, $args)
73 76
     {
74 77
         $argNames = $node->getArguments();
Please login to merge, or discard this patch.
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -22,7 +22,7 @@  discard block
 block discarded – undo
22 22
         $combined = $node->getCombined();
23 23
         $keys = array_keys($combined);
24 24
 
25
-        array_walk($keys, function ($key) use ($node, $combined) {
25
+        array_walk($keys, function($key) use ($node, $combined) {
26 26
             $value = $this->visit($combined[$key]);
27 27
             $this->context->set($key, $value);
28 28
         });
@@ -91,7 +91,7 @@  discard block
 block discarded – undo
91 91
 
92 92
     public function visitSequenceNode(Nodes\SequenceNode $node)
93 93
     {
94
-        return array_reduce($node->getNodes(), function ($prev, $next) {
94
+        return array_reduce($node->getNodes(), function($prev, $next) {
95 95
             return $this->visit($next);
96 96
         });
97 97
     }
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Parser/Tokenizer.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -83,7 +83,7 @@  discard block
 block discarded – undo
83 83
     public function tokenize($code)
84 84
     {
85 85
         // Initial state of parser
86
-        $baseIter = tail(function ($rest, $acc) use (&$baseIter, &$symbolIter, &$stringIter, &$commentIter) {
86
+        $baseIter = tail(function($rest, $acc) use (&$baseIter, &$symbolIter, &$stringIter, &$commentIter) {
87 87
             if (sizeof($rest) == 0) {
88 88
                 return $acc;
89 89
             }
@@ -115,7 +115,7 @@  discard block
 block discarded – undo
115 115
         });
116 116
 
117 117
         // State when parser parses any symbol
118
-        $symbolIter = tail(function ($rest, $buffer, $acc) use (&$symbolIter, &$baseIter, &$delimiterIter) {
118
+        $symbolIter = tail(function($rest, $buffer, $acc) use (&$symbolIter, &$baseIter, &$delimiterIter) {
119 119
             if (sizeof($rest) > 0) {
120 120
                 list ($head, $tail) = toHeadTail($rest);
121 121
                 if ($this->isSymbol($head)) {
@@ -127,7 +127,7 @@  discard block
 block discarded – undo
127 127
         });
128 128
 
129 129
         // State when parser parses string
130
-        $stringIter = tail(function ($rest, $buffer, $acc) use (&$stringIter, &$baseIter, &$escapeIter) {
130
+        $stringIter = tail(function($rest, $buffer, $acc) use (&$stringIter, &$baseIter, &$escapeIter) {
131 131
             if (sizeof($rest) == 0) {
132 132
                 throw new TokenizerException("Unexpected end of string");
133 133
             }
@@ -142,7 +142,7 @@  discard block
 block discarded – undo
142 142
         });
143 143
 
144 144
         // State when parser parses escaped symbol
145
-        $escapeIter = tail(function ($rest, $buffer, $acc) use (&$stringIter) {
145
+        $escapeIter = tail(function($rest, $buffer, $acc) use (&$stringIter) {
146 146
             if (sizeof($rest) == 0) {
147 147
                 throw new TokenizerException("Unused escape character");
148 148
             }
@@ -151,7 +151,7 @@  discard block
 block discarded – undo
151 151
         });
152 152
 
153 153
         // State when parser ignores comments
154
-        $commentIter = function ($rest, $buffer, $acc) use (&$commentIter, &$baseIter) {
154
+        $commentIter = function($rest, $buffer, $acc) use (&$commentIter, &$baseIter) {
155 155
             if (sizeof($rest) > 0) {
156 156
                 list ($head, $tail) = toHeadTail($rest);
157 157
                 if ($head != Tokenizer::TOKEN_NEW_LINE) {
@@ -172,7 +172,7 @@  discard block
 block discarded – undo
172 172
      */
173 173
     public function deflate(array $tokens)
174 174
     {
175
-        $iter = tail(function ($rest, $acc) use (&$iter) {
175
+        $iter = tail(function($rest, $acc) use (&$iter) {
176 176
             if (empty($rest)) {
177 177
                 return $acc;
178 178
             }
@@ -195,7 +195,7 @@  discard block
 block discarded – undo
195 195
 
196 196
     public function convertSequenceToNode(array $tree)
197 197
     {
198
-        return new SequenceNode(array_reduce($tree, function ($acc, $token) {
198
+        return new SequenceNode(array_reduce($tree, function($acc, $token) {
199 199
             return $this->isValuedToken($token)
200 200
                 ? append($acc, $this->convertToNode($token))
201 201
                 : $acc;
@@ -249,7 +249,7 @@  discard block
 block discarded – undo
249 249
         if (is_array($expression)) {
250 250
             list ($head, $body) = toHeadTail($expression);
251 251
 
252
-            $arguments = array_map(function ($token) {
252
+            $arguments = array_map(function($token) {
253 253
                 if (!$token instanceof SymbolToken) {
254 254
                     throw new ParserException("Lambda arguments must be a symbols");
255 255
                 }
@@ -284,7 +284,7 @@  discard block
 block discarded – undo
284 284
             throw new ParserException("Function must have a name");
285 285
         }
286 286
 
287
-        $headValues = array_map(function ($token) {
287
+        $headValues = array_map(function($token) {
288 288
             if (!$token instanceof SymbolToken) {
289 289
                 throw new ParserException("Function name and arguments must be a symbols");
290 290
             }
@@ -304,7 +304,7 @@  discard block
 block discarded – undo
304 304
 
305 305
         $chunks = array_chunk($body, 2);
306 306
 
307
-        $constants = array_reduce($chunks, function ($acc, $chunk) {
307
+        $constants = array_reduce($chunks, function($acc, $chunk) {
308 308
             list ($name, $value) = $chunk;
309 309
             if (!$name instanceof SymbolToken) {
310 310
                 throw new ParserException("Constant name must be a symbol");
@@ -317,7 +317,7 @@  discard block
 block discarded – undo
317 317
 
318 318
     private function findPairClosingBracketIndex(array $tokens)
319 319
     {
320
-        $iter = tail(function ($rest, $depth, $position) use (&$iter) {
320
+        $iter = tail(function($rest, $depth, $position) use (&$iter) {
321 321
             if (empty($rest)) {
322 322
                 throw new SyntaxException("Unpaired closing bracket found");
323 323
             }
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Modules/Relation.php 1 patch
Spacing   +17 added lines, -17 removed lines patch added patch discarded remove patch
@@ -12,7 +12,7 @@  discard block
 block discarded – undo
12 12
     if (empty($arguments)) {
13 13
         throw new RuntimeException("Too few arguments");
14 14
     }
15
-    $iter = function ($rest, $first) use (&$iter, $callback, $visitor) {
15
+    $iter = function($rest, $first) use (&$iter, $callback, $visitor) {
16 16
         if (empty($rest)) {
17 17
             return true;
18 18
         }
@@ -30,43 +30,43 @@  discard block
 block discarded – undo
30 30
 function export()
31 31
 {
32 32
     return [
33
-        '>' => new NativeNode('>', function (NodeCalculatorVisitor $visitor, array $arguments) {
34
-            return relationReduce($visitor, function ($first, $second) {
33
+        '>' => new NativeNode('>', function(NodeCalculatorVisitor $visitor, array $arguments) {
34
+            return relationReduce($visitor, function($first, $second) {
35 35
                 return $first > $second;
36 36
             }, $arguments);
37 37
         }),
38
-        '<' => new NativeNode('<', function (NodeCalculatorVisitor $visitor, array $arguments) {
39
-            return relationReduce($visitor, function ($first, $second) {
38
+        '<' => new NativeNode('<', function(NodeCalculatorVisitor $visitor, array $arguments) {
39
+            return relationReduce($visitor, function($first, $second) {
40 40
                 return $first < $second;
41 41
             }, $arguments);
42 42
         }),
43
-        '>=' => new NativeNode('>=', function (NodeCalculatorVisitor $visitor, array $arguments) {
44
-            return relationReduce($visitor, function ($first, $second) {
43
+        '>=' => new NativeNode('>=', function(NodeCalculatorVisitor $visitor, array $arguments) {
44
+            return relationReduce($visitor, function($first, $second) {
45 45
                 return $first >= $second;
46 46
             }, $arguments);
47 47
         }),
48
-        '<=' => new NativeNode('<=', function (NodeCalculatorVisitor $visitor, array $arguments) {
49
-            return relationReduce($visitor, function ($first, $second) {
48
+        '<=' => new NativeNode('<=', function(NodeCalculatorVisitor $visitor, array $arguments) {
49
+            return relationReduce($visitor, function($first, $second) {
50 50
                 return $first <= $second;
51 51
             }, $arguments);
52 52
         }),
53
-        '=' => new NativeNode('=', function (NodeCalculatorVisitor $visitor, array $arguments) {
54
-            return relationReduce($visitor, function ($first, $second) {
53
+        '=' => new NativeNode('=', function(NodeCalculatorVisitor $visitor, array $arguments) {
54
+            return relationReduce($visitor, function($first, $second) {
55 55
                 return $first == $second;
56 56
             }, $arguments);
57 57
         }),
58
-        '==' => new NativeNode('==', function (NodeCalculatorVisitor $visitor, array $arguments) {
59
-            return relationReduce($visitor, function ($first, $second) {
58
+        '==' => new NativeNode('==', function(NodeCalculatorVisitor $visitor, array $arguments) {
59
+            return relationReduce($visitor, function($first, $second) {
60 60
                 return $first === $second;
61 61
             }, $arguments);
62 62
         }),
63
-        '!=' => new NativeNode('!=', function (NodeCalculatorVisitor $visitor, array $arguments) {
64
-            return relationReduce($visitor, function ($first, $second) {
63
+        '!=' => new NativeNode('!=', function(NodeCalculatorVisitor $visitor, array $arguments) {
64
+            return relationReduce($visitor, function($first, $second) {
65 65
                 return $first != $second;
66 66
             }, $arguments);
67 67
         }),
68
-        '!==' => new NativeNode('!==', function (NodeCalculatorVisitor $visitor, array $arguments) {
69
-            return relationReduce($visitor, function ($first, $second) {
68
+        '!==' => new NativeNode('!==', function(NodeCalculatorVisitor $visitor, array $arguments) {
69
+            return relationReduce($visitor, function($first, $second) {
70 70
                 return $first !== $second;
71 71
             }, $arguments);
72 72
         })
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Modules/Math.php 1 patch
Spacing   +11 added lines, -11 removed lines patch added patch discarded remove patch
@@ -10,17 +10,17 @@  discard block
 block discarded – undo
10 10
 function export()
11 11
 {
12 12
     return [
13
-        '+' => new NativeNode('+', function (NodeCalculatorVisitor $visitor, array $arguments) {
14
-            return array_reduce($arguments, function ($result, $argument) use ($visitor) {
13
+        '+' => new NativeNode('+', function(NodeCalculatorVisitor $visitor, array $arguments) {
14
+            return array_reduce($arguments, function($result, $argument) use ($visitor) {
15 15
                 return $result + $visitor->valueOf($argument);
16 16
             }, 0);
17 17
         }),
18
-        '*' => new NativeNode('*', function (NodeCalculatorVisitor $visitor, array $arguments) {
19
-            return array_reduce($arguments, function ($result, $argument) use ($visitor) {
18
+        '*' => new NativeNode('*', function(NodeCalculatorVisitor $visitor, array $arguments) {
19
+            return array_reduce($arguments, function($result, $argument) use ($visitor) {
20 20
                 return $result * $visitor->valueOf($argument);
21 21
             }, 1);
22 22
         }),
23
-        '-' => new NativeNode('-', function (NodeCalculatorVisitor $visitor, array $arguments) {
23
+        '-' => new NativeNode('-', function(NodeCalculatorVisitor $visitor, array $arguments) {
24 24
             if (sizeof($arguments) == 0) {
25 25
                 throw new RuntimeException("Too few arguments");
26 26
             }
@@ -28,11 +28,11 @@  discard block
 block discarded – undo
28 28
             if (empty($tail)) {
29 29
                 return -$visitor->valueOf($head);
30 30
             }
31
-            return array_reduce($tail, function ($result, $argument) use ($visitor) {
31
+            return array_reduce($tail, function($result, $argument) use ($visitor) {
32 32
                 return $result - $visitor->valueOf($argument);
33 33
             }, $visitor->valueOf($head));
34 34
         }),
35
-        '/' => new NativeNode('/', function (NodeCalculatorVisitor $visitor, array $arguments) {
35
+        '/' => new NativeNode('/', function(NodeCalculatorVisitor $visitor, array $arguments) {
36 36
             if (sizeof($arguments) == 0) {
37 37
                 throw new RuntimeException("Too few arguments");
38 38
             }
@@ -40,23 +40,23 @@  discard block
 block discarded – undo
40 40
             if (empty($tail)) {
41 41
                 return 1 / $visitor->valueOf($head);
42 42
             }
43
-            return array_reduce($tail, function ($result, $argument) use ($visitor) {
43
+            return array_reduce($tail, function($result, $argument) use ($visitor) {
44 44
                 return $result / $visitor->valueOf($argument);
45 45
             }, $visitor->valueOf($head));
46 46
         }),
47
-        '%' => new NativeNode('%', function (NodeCalculatorVisitor $visitor, array $arguments) {
47
+        '%' => new NativeNode('%', function(NodeCalculatorVisitor $visitor, array $arguments) {
48 48
             if (sizeof($arguments) != 2) {
49 49
                 throw new RuntimeException("Modulo operation requires exactly two arguments");
50 50
             }
51 51
             list ($number, $div) = $arguments;
52 52
             return $visitor->valueOf($number) % $visitor->valueOf($div);
53 53
         }),
54
-        'pow' => new NativeNode('pow', function (NodeCalculatorVisitor $visitor, array $arguments) {
54
+        'pow' => new NativeNode('pow', function(NodeCalculatorVisitor $visitor, array $arguments) {
55 55
             if (sizeof($arguments) < 2) {
56 56
                 throw new RuntimeException("Function \"pow\" requires at least two arguments");
57 57
             }
58 58
             list ($head, $tail) = toHeadTail($arguments);
59
-            return array_reduce($tail, function ($result, $argument) use ($visitor) {
59
+            return array_reduce($tail, function($result, $argument) use ($visitor) {
60 60
                 return pow($result, $visitor->valueOf($argument));
61 61
             }, $visitor->valueOf($head));
62 62
         })
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Modules/Stdio.php 1 patch
Spacing   +5 added lines, -5 removed lines patch added patch discarded remove patch
@@ -10,7 +10,7 @@  discard block
 block discarded – undo
10 10
 function export()
11 11
 {
12 12
     return [
13
-        'input' => new NativeNode('input', function (NodeCalculatorVisitor $visitor, array $arguments) {
13
+        'input' => new NativeNode('input', function(NodeCalculatorVisitor $visitor, array $arguments) {
14 14
             if (empty($arguments)) {
15 15
                 throw new RuntimeException('Function expects one argument, but none given');
16 16
             }
@@ -18,13 +18,13 @@  discard block
 block discarded – undo
18 18
             echo ' ';
19 19
             return new StringNode(trim(fgets(STDIN)));
20 20
         }),
21
-        'print' => new NativeNode('print', function (NodeCalculatorVisitor $visitor, array $arguments) {
22
-            array_walk($arguments, function ($argument) use ($visitor) {
21
+        'print' => new NativeNode('print', function(NodeCalculatorVisitor $visitor, array $arguments) {
22
+            array_walk($arguments, function($argument) use ($visitor) {
23 23
                 echo $visitor->valueOf($argument);
24 24
             });
25 25
         }),
26
-        'println' => new NativeNode('print', function (NodeCalculatorVisitor $visitor, array $arguments) {
27
-            array_walk($arguments, function ($argument) use ($visitor) {
26
+        'println' => new NativeNode('print', function(NodeCalculatorVisitor $visitor, array $arguments) {
27
+            array_walk($arguments, function($argument) use ($visitor) {
28 28
                 echo $visitor->valueOf($argument);
29 29
             });
30 30
             echo PHP_EOL;
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Modules/Strings.php 1 patch
Spacing   +2 added lines, -2 removed lines patch added patch discarded remove patch
@@ -10,8 +10,8 @@
 block discarded – undo
10 10
 function export()
11 11
 {
12 12
     return [
13
-        'concat' => new NativeNode('input', function (NodeCalculatorVisitor $visitor, array $arguments) {
14
-            return array_reduce($arguments, function ($acc, $arg) use ($visitor) {
13
+        'concat' => new NativeNode('input', function(NodeCalculatorVisitor $visitor, array $arguments) {
14
+            return array_reduce($arguments, function($acc, $arg) use ($visitor) {
15 15
                 return $acc . $visitor->valueOf($arg);
16 16
             }, '');
17 17
         })
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Modules/Logic.php 1 patch
Spacing   +8 added lines, -8 removed lines patch added patch discarded remove patch
@@ -11,8 +11,8 @@  discard block
 block discarded – undo
11 11
 function export()
12 12
 {
13 13
     return [
14
-        'or' => new NativeNode('or', function (NodeCalculatorVisitor $visitor, array $arguments) {
15
-            $iter = function ($rest) use (&$iter, $visitor) {
14
+        'or' => new NativeNode('or', function(NodeCalculatorVisitor $visitor, array $arguments) {
15
+            $iter = function($rest) use (&$iter, $visitor) {
16 16
                 if (empty($rest)) {
17 17
                     return false;
18 18
                 }
@@ -21,8 +21,8 @@  discard block
 block discarded – undo
21 21
             };
22 22
             return $iter($arguments);
23 23
         }),
24
-        'and' => new NativeNode('and', function (NodeCalculatorVisitor $visitor, array $arguments) {
25
-            $iter = function ($rest) use (&$iter, $visitor) {
24
+        'and' => new NativeNode('and', function(NodeCalculatorVisitor $visitor, array $arguments) {
25
+            $iter = function($rest) use (&$iter, $visitor) {
26 26
                 if (empty($rest)) {
27 27
                     return true;
28 28
                 }
@@ -31,12 +31,12 @@  discard block
 block discarded – undo
31 31
             };
32 32
             return $iter($arguments);
33 33
         }),
34
-        'not' => new NativeNode('not', function (NodeCalculatorVisitor $visitor, array $arguments) {
35
-            return all($arguments, function ($argument) use ($visitor) {
34
+        'not' => new NativeNode('not', function(NodeCalculatorVisitor $visitor, array $arguments) {
35
+            return all($arguments, function($argument) use ($visitor) {
36 36
                 return !$visitor->visit($argument);
37 37
             });
38 38
         }),
39
-        'if' => new NativeNode('if', function (NodeCalculatorVisitor $visitor, array $arguments) {
39
+        'if' => new NativeNode('if', function(NodeCalculatorVisitor $visitor, array $arguments) {
40 40
             if (sizeof($arguments) != 3) {
41 41
                 throw new RuntimeException("Function 'if' accepts only three arguments");
42 42
             }
@@ -45,7 +45,7 @@  discard block
 block discarded – undo
45 45
                 ? $visitor->visit($onTrue)
46 46
                 : $visitor->visit($onFalse);
47 47
         }),
48
-        'unless' => new NativeNode('unless', function (NodeCalculatorVisitor $visitor, array $arguments) {
48
+        'unless' => new NativeNode('unless', function(NodeCalculatorVisitor $visitor, array $arguments) {
49 49
             if (sizeof($arguments) != 3) {
50 50
                 throw new RuntimeException("Function 'unless' accepts only three arguments");
51 51
             }
Please login to merge, or discard this patch.
src/PeacefulBit/Packet/Visitors/NodePrinterVisitor.php 1 patch
Spacing   +1 added lines, -1 removed lines patch added patch discarded remove patch
@@ -13,7 +13,7 @@
 block discarded – undo
13 13
         $names = $node->getNames();
14 14
         $values = $node->getValues();
15 15
 
16
-        $zippedArguments = array_map(function ($name, $value) {
16
+        $zippedArguments = array_map(function($name, $value) {
17 17
             return implode(' ', [$name, $this->visit($value)]);
18 18
         }, $names, $values);
19 19
 
Please login to merge, or discard this patch.