Group::accept()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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\Group as GroupNode;
7
use Apicart\FQL\Value\AbstractNode;
8
use LogicException;
9
10
final class Group extends AbstractVisitor
11
{
12
13 134
    public function accept(AbstractNode $node): bool
14
    {
15 134
        return $node instanceof GroupNode;
16
    }
17
18
19 23
    public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ?array $options = null): string
20
    {
21 23
        if (! $node instanceof GroupNode) {
22
            throw new LogicException('Implementation accepts instance of Group Node');
23
        }
24 23
        if ($subVisitor === null) {
25
            throw new LogicException('Implementation requires sub-visitor');
26
        }
27 23
        $clauses = [];
28 23
        foreach ($node->getNodes() as $subNode) {
29 23
            $clauses[] = $subVisitor->visit($subNode, $subVisitor, $options);
30
        }
31 23
        $clauses = implode(' ', $clauses);
32 23
        $tokenLeft = $node->getTokenLeft();
33 23
        $tokenRight = $node->getTokenRight();
34
35 23
        $domainPrefix = $tokenLeft === null || $tokenLeft->getDomain() === '' ? '' : "{$tokenLeft->getDomain()}:";
36 23
        $delimiter = $tokenLeft === null ? '' : $tokenLeft->getDelimiter();
37 23
        $lexeme = $tokenRight === null ? '' : $tokenRight->getLexeme();
38
39 23
        return "{$domainPrefix}{$delimiter}{$clauses}{$lexeme}";
40
    }
41
42
}
43