ReturnClause::compile()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 2

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 3
b 0
f 0
nc 2
nop 1
dl 0
loc 13
ccs 8
cts 8
cp 1
crap 2
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