UnaryOperator   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 23
Duplicated Lines 0 %

Test Coverage

Coverage 83.33%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
c 1
b 0
f 0
dl 0
loc 23
ccs 10
cts 12
cp 0.8333
rs 10
wmc 9

2 Methods

Rating   Name   Duplication   Size   Complexity  
A visit() 0 14 6
A accept() 0 3 3
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\LogicalNot;
7
use Apicart\FQL\Token\Node\Mandatory;
8
use Apicart\FQL\Token\Node\Prohibited;
9
use Apicart\FQL\Tokenizer\Tokenizer;
10
use Apicart\FQL\Value\AbstractNode;
11
use LogicException;
12
13
final class UnaryOperator extends AbstractVisitor
14
{
15
16 133
    public function accept(AbstractNode $node): bool
17
    {
18 133
        return $node instanceof Mandatory || $node instanceof Prohibited || $node instanceof LogicalNot;
19
    }
20
21
22 81
    public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ?array $options = null): string
23
    {
24 81
        if (! $node instanceof Mandatory && ! $node instanceof Prohibited && ! $node instanceof LogicalNot) {
25
            throw new LogicException('Implementation accepts instance of Mandatory, Prohibited or LogicalNot Node');
26
        }
27 81
        if ($subVisitor === null) {
28
            throw new LogicException('Implementation requires sub-visitor');
29
        }
30 81
        $clause = $subVisitor->visit($node->getOperand(), $subVisitor, $options);
31 81
        $padding = '';
32 81
        if ($node->getToken()->getType() === Tokenizer::TOKEN_LOGICAL_NOT) {
33 26
            $padding = ' ';
34
        }
35 81
        return "{$node->getToken()->getLexeme()}{$padding}{$clause}";
36
    }
37
38
}
39