Failed Conditions
Branch prepare-alpha (4a2a7f)
by Bas
02:41
created

EdgeCollectionsClause::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

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