ReturnClause   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 13
c 3
b 0
f 0
dl 0
loc 34
ccs 12
cts 12
cp 1
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 8 1
A compile() 0 13 2
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