EdgeCollectionsClause   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 45
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 16
c 3
b 0
f 0
dl 0
loc 45
ccs 16
cts 16
cp 1
rs 10
wmc 6

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A compile() 0 23 5
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