ListExpression::compile()   A
last analyzed

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 3

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 3
eloc 7
c 2
b 0
f 0
nc 4
nop 1
dl 0
loc 18
ccs 8
cts 8
cp 1
crap 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Expressions;
6
7
use LaravelFreelancerNL\FluentAQL\Exceptions\ExpressionTypeException;
8
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
9
10
/**
11
 * List expression.
12
 */
13
class ListExpression extends Expression implements ExpressionInterface
14
{
15
    /**
16
     * @psalm-suppress MixedArgumentTypeCoercion
17
     *
18
     * @param array<array-key, null|object|scalar>|Expression $expression
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<array-key, null|object|scalar>|Expression at position 2 could not be parsed: Unknown type name 'array-key' at position 2 in array<array-key, null|object|scalar>|Expression.
Loading history...
19
     */
20 1
    public function __construct(
21
        array|Expression $expression
22
    ) {
23 1
        $this->expression = $expression;
24
    }
25
26
    /**
27
     * @throws ExpressionTypeException
28
     */
29 1
    public function compile(QueryBuilder $queryBuilder): string
30
    {
31
        /** @var array<array-key, Expression> $expressions */
32 1
        $expressions = [];
33
        /**
34
         * @var array-key $key
35
         * @var mixed $value
36
         */
37 1
        foreach ($this->expression as $key => $value) {
38 1
            $expressions[$key] = $queryBuilder->normalizeArgument($value);
39
        }
40
41 1
        $outputStrings = [];
42 1
        foreach ($expressions as $expressionElement) {
43 1
            $outputStrings[] = $expressionElement->compile($queryBuilder);
44
        }
45
46 1
        return '[' . implode(',', $outputStrings) . ']';
47
    }
48
}
49