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 1
Metric Value
cc 1
eloc 1
c 1
b 0
f 1
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\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