Passed
Branch next (ee2197)
by Bas
02:37
created

ForClause   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 52
Duplicated Lines 0 %

Test Coverage

Coverage 95.45%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 22
c 3
b 0
f 0
dl 0
loc 52
ccs 21
cts 22
cp 0.9545
rs 10
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 12 2
A compile() 0 22 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Clauses;
6
7
use LaravelFreelancerNL\FluentAQL\Expressions\Expression;
8
use LaravelFreelancerNL\FluentAQL\Expressions\ExpressionInterface;
9
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
10
11
class ForClause extends Clause
12
{
13
    /**
14
     * @var array<mixed>
15
     */
16
    protected array $variables;
17
18
    /**
19
     * @var array<mixed>|Expression|ExpressionInterface|QueryBuilder|string|null
20
     */
21
    protected array|Expression|ExpressionInterface|QueryBuilder|string|null $in;
0 ignored issues
show
Bug introduced by
The type LaravelFreelancerNL\FluentAQL\Clauses\null was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
22
23
    /**
24
     * @param array<mixed>|string|Expression $variables
25
     * @param array<mixed>|string|QueryBuilder|Expression|null $in
26
     */
27 22
    public function __construct(
28
        array|string|Expression $variables,
29
        array|string|QueryBuilder|Expression $in = null
30
    ) {
31 22
        parent::__construct();
32
33 22
        if (!is_array($variables)) {
0 ignored issues
show
introduced by
The condition is_array($variables) is always true.
Loading history...
34
            $variables = [$variables];
35
        }
36 22
        $this->variables = $variables;
37
38 22
        $this->in = $in;
39 22
    }
40
41 22
    public function compile(QueryBuilder $queryBuilder): string
42
    {
43 22
        foreach ($this->variables as $key => $value) {
44 22
            $this->variables [$key] = $queryBuilder->normalizeArgument($value, 'Variable');
45 22
            $queryBuilder->registerVariable($this->variables[$key]->compile($queryBuilder));
46
        }
47 22
        $variableExpression =  array_map(function ($variable) use ($queryBuilder) {
48 22
            return $variable->compile($queryBuilder);
49 22
        }, $this->variables);
50
51 22
        $variableExpression = implode(', ', $variableExpression);
52
53 22
        $inExpression = '';
54 22
        if ($this->in !== null) {
55 22
            $this->in = $queryBuilder->normalizeArgument(
56 22
                $this->in,
57 22
                ['Collection', 'Range', 'List', 'Reference', 'Query', 'CollectionBind']
58
            );
59 22
            $inExpression = $this->in->compile($queryBuilder);
60
        }
61
62 22
        return "FOR {$variableExpression} IN {$inExpression}";
63
    }
64
}
65