| Conditions | 4 |
| Paths | 6 |
| Total Lines | 21 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 13 |
| CRAP Score | 4 |
| Changes | 0 | ||
| 1 | <?php |
||
| 37 | 6 | public function applyToNode(Node $node) |
|
| 38 | { |
||
| 39 | 6 | $expression = $node->getInstruction($this); |
|
| 40 | 6 | $variables = $node->getResult() ?: []; |
|
| 41 | |||
| 42 | 6 | $arithmetic = new Hoa\Math\Visitor\Arithmetic(); |
|
| 43 | |||
| 44 | 6 | foreach ($variables as $name => $value) { |
|
| 45 | // Constants are upper case and variables lower case. We don't really care, so using a workaround. |
||
| 46 | 2 | if (preg_match('/^[A-Z_][A-Z0-9_]*$/', $name)) { |
|
| 47 | 1 | $arithmetic->addConstant($name, $value); |
|
| 48 | 1 | } else { |
|
| 49 | $arithmetic->addVariable($name, function() use ($value) { return $value; }); |
||
| 50 | } |
||
| 51 | 6 | } |
|
| 52 | |||
| 53 | 6 | $ast = $this->parser->parse($expression); |
|
| 54 | 5 | $result = $arithmetic->visit($ast); |
|
| 55 | |||
| 56 | 4 | $node->setResult($result); |
|
| 57 | 4 | } |
|
| 58 | } |
||
| 59 |