Conditions | 7 |
Paths | 7 |
Total Lines | 25 |
Code Lines | 16 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
43 | public function accept(Visitor $visitor) |
||
44 | { |
||
45 | /** @var int|float $leftValue */ |
||
46 | $leftValue = $visitor->visit($this->left); |
||
47 | /** @var int|float $rightValue */ |
||
48 | $rightValue = $visitor->visit($this->right); |
||
49 | switch ($this->operator->type) { |
||
50 | case Token::PLUS: |
||
51 | return $leftValue + $rightValue; |
||
52 | case Token::MINUS; |
||
53 | return $leftValue - $rightValue; |
||
54 | case Token::MUL; |
||
55 | return $leftValue * $rightValue; |
||
56 | case Token::POWER: |
||
57 | return $leftValue ** $rightValue; |
||
58 | case Token::REALDIV; |
||
59 | //not strict for int/float |
||
60 | /** @noinspection TypeUnsafeComparisonInspection */ |
||
61 | if ($rightValue == 0) { |
||
62 | throw new DivisionByZeroException('Division be zero not allowed'); |
||
63 | } |
||
64 | return $leftValue / $rightValue; |
||
65 | } |
||
66 | |||
67 | throw new VisitorException('Unknown operator for BinaryOperator'); |
||
68 | } |
||
69 | } |