Group::visit()   A
last analyzed

Complexity

Conditions 5
Paths 12

Size

Total Lines 21
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 5
eloc 12
c 1
b 0
f 1
nc 12
nop 3
dl 0
loc 21
ccs 13
cts 13
cp 1
crap 5
rs 9.5555
1
<?php declare(strict_types = 1);
2
3
namespace Apicart\FQL\Generator\SQL;
4
5
use Apicart\FQL\Generator\Common\AbstractVisitor;
6
use Apicart\FQL\Token\Node\Group as GroupNode;
7
use Apicart\FQL\Value\AbstractNode;
8
9
final class Group extends AbstractVisitor
10
{
11
12 1
    public function accept(AbstractNode $node): bool
13
    {
14 1
        return $node instanceof GroupNode;
15
    }
16
17
18 1
    public function visit(AbstractNode $node, ?AbstractVisitor $subVisitor = null, ?array $options = null): string
19
    {
20
        /** @var GroupNode $groupNode */
21 1
        $groupNode = $node;
22
23 1
        $clauses = [];
24 1
        foreach ($groupNode->getNodes() as $subNode) {
25 1
            $options['parent'] = $node;
26 1
            if ($subVisitor !== null) {
27 1
                $clauses[] = $subVisitor->visit($subNode, $subVisitor, $options);
28
            }
29
        }
30
31 1
        $clauses = implode(' ', $clauses);
32 1
        $tokenLeft = $groupNode->getTokenLeft();
33 1
        $tokenRight = $groupNode->getTokenRight();
34
35 1
        $delimiter = $tokenLeft === null ? '' : $tokenLeft->getDelimiter();
36 1
        $lexeme = $tokenRight === null ? '' : $tokenRight->getLexeme();
37
38 1
        return "{$delimiter}{$clauses}{$lexeme}";
39
    }
40
41
}
42