Completed
Pull Request — master (#122)
by Enrico
03:22
created

BitwiseXor::compile()   C

Complexity

Conditions 7
Paths 13

Size

Total Lines 23
Code Lines 16

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 56

Importance

Changes 0
Metric Value
cc 7
eloc 16
c 0
b 0
f 0
nc 13
nop 2
dl 0
loc 23
ccs 0
cts 18
cp 0
crap 56
rs 6.7272
1
<?php
2
3
namespace PHPSA\Compiler\Expression\AssignOp;
4
5
use PHPSA\CompiledExpression;
6
use PHPSA\Compiler\Expression;
7
use PHPSA\Compiler\Expression\AbstractExpressionCompiler;
8
use PHPSA\Context;
9
10
class BitwiseXor extends AbstractExpressionCompiler
11
{
12
    protected $name = 'PhpParser\Node\Expr\AssignOp\BitwiseXor';
13
14
    /**
15
     * {left-expr} ^= {right-expr}
16
     *
17
     * @param \PhpParser\Node\Expr\AssignOp\BitwiseXor $expr
18
     * @param Context $context
19
     * @return CompiledExpression
20
     */
21
    protected function compile($expr, Context $context)
22
    {
23
        $left = $context->getExpressionCompiler()->compile($expr->var);
24
        $expExpression = $context->getExpressionCompiler()->compile($expr->expr);
25
26
        switch ($left->getType()) {
27
            case CompiledExpression::INTEGER:
28
            case CompiledExpression::DOUBLE:
29
            case CompiledExpression::NUMBER:
30
                switch ($expExpression->getType()) {
31
                    case CompiledExpression::INTEGER:
32
                    case CompiledExpression::DOUBLE:
33
                    case CompiledExpression::NUMBER:
34
                        return CompiledExpression::fromZvalValue(
35
                            $left->getValue() ^ $expExpression->getValue()
36
                        );
37
                        break;
0 ignored issues
show
Unused Code introduced by
break is not strictly necessary here and could be removed.

The break statement is not necessary if it is preceded for example by a return statement:

switch ($x) {
    case 1:
        return 'foo';
        break; // This break is not necessary and can be left off.
}

If you would like to keep this construct to be consistent with other case statements, you can safely mark this issue as a false-positive.

Loading history...
38
                }
39
                break;
40
        }
41
42
        return new CompiledExpression(CompiledExpression::UNKNOWN);
43
    }
44
}
45