Passed
Pull Request — master (#12)
by Bas
02:32
created

IntoClause::compile()   A

Complexity

Conditions 3
Paths 4

Size

Total Lines 18
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 3

Importance

Changes 0
Metric Value
cc 3
eloc 10
nc 4
nop 1
dl 0
loc 18
ccs 11
cts 11
cp 1
crap 3
rs 9.9332
c 0
b 0
f 0
1
<?php
2
3
namespace LaravelFreelancerNL\FluentAQL\Clauses;
4
5
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
6
7
class IntoClause extends Clause
8
{
9
10
    protected $groupsVariable;
11
12
    protected $projectionExpression;
13
14 1
    public function __construct($groupsVariable, $projectionExpression = null)
15
    {
16 1
        $this->groupsVariable = $groupsVariable;
17 1
        $this->projectionExpression = $projectionExpression;
18 1
    }
19
20 1
    public function compile(QueryBuilder $queryBuilder): string
21
    {
22 1
        $this->groupsVariable = $queryBuilder->normalizeArgument($this->groupsVariable, 'Variable');
0 ignored issues
show
Bug introduced by
'Variable' of type string is incompatible with the type array|null expected by parameter $allowedExpressionTypes of LaravelFreelancerNL\Flue...er::normalizeArgument(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

22
        $this->groupsVariable = $queryBuilder->normalizeArgument($this->groupsVariable, /** @scrutinizer ignore-type */ 'Variable');
Loading history...
23 1
        $queryBuilder->registerVariable($this->groupsVariable);
0 ignored issues
show
Bug introduced by
$this->groupsVariable of type LaravelFreelancerNL\Flue...\Expressions\Expression is incompatible with the type array|string expected by parameter $variableName of LaravelFreelancerNL\Flue...der::registerVariable(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

23
        $queryBuilder->registerVariable(/** @scrutinizer ignore-type */ $this->groupsVariable);
Loading history...
24
25 1
        if (isset($this->projectionExpression)) {
26 1
            $this->projectionExpression = $queryBuilder->normalizeArgument(
27 1
                $this->projectionExpression,
28 1
                ['Reference', 'Object', 'Function', 'Query', 'Bind']
29
            );
30
        }
31
32 1
        $output = 'INTO ' . $this->groupsVariable->compile($queryBuilder);
33 1
        if (isset($this->projectionExpression)) {
34 1
            $output .= ' = ' . $this->projectionExpression->compile($queryBuilder);
35
        }
36
37 1
        return $output;
38
    }
39
}
40