BinaryOperator   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 22
ccs 8
cts 10
cp 0.8
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visit() 0 13 4
A accept() 0 3 2
1
<?php declare(strict_types = 1);
2
3
namespace Apicart\FQL\Generator\Native;
4
5
use Apicart\FQL\Generator\Common\AbstractVisitor;
6
use Apicart\FQL\Token\Node\LogicalAnd;
7
use Apicart\FQL\Token\Node\LogicalOr;
8
use Apicart\FQL\Value\AbstractNode;
9
use LogicException;
10
11
final class BinaryOperator extends AbstractVisitor
12
{
13
14 134
    public function accept(AbstractNode $node): bool
15
    {
16 134
        return $node instanceof LogicalAnd || $node instanceof LogicalOr;
17
    }
18
19
20 48
    public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ?array $options = null): string
21
    {
22 48
        if (! $node instanceof LogicalAnd && ! $node instanceof LogicalOr) {
23
            throw new LogicException('Implementation accepts instance of LogicalAnd or LogicalOr Node');
24
        }
25 48
        if ($subVisitor === null) {
26
            throw new LogicException('Implementation requires sub-visitor');
27
        }
28
        $clauses = [
29 48
            $subVisitor->visit($node->getLeftOperand(), $subVisitor, $options),
30 48
            $subVisitor->visit($node->getRightOperand(), $subVisitor, $options),
31
        ];
32 48
        return implode(" {$node->getToken()->getLexeme()} ", $clauses);
33
    }
34
35
}
36