EdgeCollectionsClause::compile()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 23
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 13
CRAP Score 5

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 5
eloc 12
c 3
b 0
f 0
nc 5
nop 1
dl 0
loc 23
ccs 13
cts 13
cp 1
crap 5
rs 9.5555
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Clauses;
6
7
use LaravelFreelancerNL\FluentAQL\Exceptions\ExpressionTypeException;
8
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
9
use LaravelFreelancerNL\FluentAQL\Expressions\ExpressionInterface;
10
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
11
12
class EdgeCollectionsClause extends Clause
13
{
14
    /**
15
     * @var array<array<string>|Expression> $edgeCollections
16
     */
17
    protected array $edgeCollections;
18
19
    /**
20
     * @param array<array<string>|Expression> $edgeCollections
21
     */
22 3
    public function __construct(array $edgeCollections)
23
    {
24 3
        parent::__construct();
25
26 3
        $this->edgeCollections = $edgeCollections;
27
    }
28
29
    /**
30
     * @SuppressWarnings(PHPMD.UndefinedVariable)
31
     *
32
     * @throws ExpressionTypeException
33
     */
34 3
    public function compile(QueryBuilder $queryBuilder): string
35
    {
36
        /** @var array<string|Expression> $edgeCollections */
37 3
        $edgeCollections = array_map(function ($edgeCollection) use ($queryBuilder) {
38 3
            if (!$queryBuilder->grammar->isGraphDirection($edgeCollection)) {
39 3
                return $queryBuilder->normalizeArgument($edgeCollection, ['Collection', 'Query', 'Bind']);
40
            }
41
42 1
            return $edgeCollection;
43 3
        }, $this->edgeCollections);
44
45 3
        $output = '';
46 3
        foreach ($edgeCollections as $value) {
47 3
            if ($value instanceof ExpressionInterface) {
48 3
                $output .= $value->compile($queryBuilder) . ', ';
49
            }
50
51 3
            if (is_string($value)) {
52 1
                $output .= $value . ' ';
53
            }
54
        }
55
56 3
        return rtrim($output, ', ');
57
    }
58
}
59