ReturnClause::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 8
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 1
eloc 3
c 3
b 0
f 0
nc 1
nop 2
dl 0
loc 8
ccs 4
cts 4
cp 1
crap 1
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace LaravelFreelancerNL\FluentAQL\Clauses;
6
7
use LaravelFreelancerNL\FluentAQL\QueryBuilder;
8
9
class ReturnClause extends Clause
10
{
11
    protected mixed $expression;
12
13
    protected bool $distinct;
14
15
    /**
16
     * ReturnClause constructor.
17
     *
18
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
19
     */
20 8
    public function __construct(
21
        mixed $expression,
22
        bool $distinct = false
23
    ) {
24 8
        parent::__construct();
25
26 8
        $this->expression = $expression;
27 8
        $this->distinct = $distinct;
28
    }
29
30 8
    public function compile(QueryBuilder $queryBuilder): string
31
    {
32 8
        $this->expression = $queryBuilder->normalizeArgument(
33 8
            $this->expression,
34 8
            ['Boolean', 'Object', 'List', 'Function', 'Variable', 'Reference', 'Query', 'Bind']
35
        );
36
37 8
        $output = 'RETURN';
38 8
        if ($this->distinct) {
39 1
            $output .= ' DISTINCT';
40
        }
41
42 8
        return $output . ' ' . $this->expression->compile($queryBuilder);
43
    }
44
}
45