LimitClause   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 2
A compile() 0 14 2
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\QueryBuilder;
9
10
class LimitClause extends Clause
11
{
12
    protected int|QueryBuilder|Expression $count;
13
14
    protected null|int|QueryBuilder|Expression $offset;
15
16 1
    public function __construct(
17
        int|QueryBuilder|Expression $offsetOrCount,
18
        int|QueryBuilder|Expression $count = null
19
    ) {
20 1
        $this->count = $offsetOrCount;
21 1
        $this->offset = null;
22
23 1
        if ($count !== null) {
24 1
            $this->count = $count;
25 1
            $this->offset = $offsetOrCount;
26
        }
27
    }
28
29 1
    public function compile(QueryBuilder $queryBuilder): string
30
    {
31 1
        $this->count = $queryBuilder->normalizeArgument($this->count, ['Number', 'Reference', 'Query', 'Bind']);
32
33
34
35 1
        $output = 'LIMIT ';
36 1
        if ($this->offset !== null) {
37 1
            $this->offset = $queryBuilder->normalizeArgument($this->offset, ['Number', 'Reference', 'Query', 'Bind']);
38
39 1
            $output .= $this->offset->compile($queryBuilder) . ', ';
40
        }
41
42 1
        return $output . $this->count->compile($queryBuilder);
43
    }
44
}
45