Test Failed
Pull Request — dev (#70)
by Wilmer
03:32
created

DQLQueryBuilder   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 20
c 1
b 0
f 0
dl 0
loc 49
ccs 15
cts 15
cp 1
rs 10
wmc 8

4 Methods

Rating   Name   Duplication   Size   Complexity  
A selectExists() 0 3 1
A defaultExpressionBuilders() 0 5 1
A buildOrderByAndLimit() 0 26 5
A __construct() 0 6 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle;
6
7
use Yiisoft\Db\Oracle\Builder\InConditionBuilder;
8
use Yiisoft\Db\Oracle\Builder\LikeConditionBuilder;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Oracle\Builder\LikeConditionBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
9
use Yiisoft\Db\Query\Conditions\InCondition;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\Conditions\InCondition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
10
use Yiisoft\Db\Query\Conditions\LikeCondition;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\Conditions\LikeCondition was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
11
use Yiisoft\Db\Query\DQLQueryBuilder as AbstractDQLQueryBuilder;
0 ignored issues
show
Bug introduced by
The type Yiisoft\Db\Query\DQLQueryBuilder was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
use Yiisoft\Db\Query\QueryBuilderInterface;
13
use Yiisoft\Db\Schema\QuoterInterface;
14
use Yiisoft\Db\Schema\SchemaInterface;
15
16
use function array_merge;
17
use function implode;
18 166
19
final class DQLQueryBuilder extends AbstractDQLQueryBuilder
20 166
{
21
    public function __construct(
22 166
        QueryBuilderInterface $queryBuilder,
23 6
        QuoterInterface $quoter,
24
        SchemaInterface $schema
25
    ) {
26 166
        parent::__construct($queryBuilder, $quoter, $schema);
27
    }
28 166
29 1
    public function buildOrderByAndLimit(string $sql, array $orderBy, $limit, $offset, array &$params = []): string
30
    {
31
        $orderByString = $this->buildOrderBy($orderBy, $params);
32 166
33 9
        if ($orderByString !== '') {
34
            $sql .= $this->separator . $orderByString;
35
        }
36 166
37 160
        $filters = [];
38
39
        if ($this->hasOffset($offset)) {
40 9
            $filters[] = 'rowNumId > ' . (string) $offset;
41
        }
42
43
        if ($this->hasLimit($limit)) {
44
            $filters[] = 'rownum <= ' . (string) $limit;
45
        }
46
47 1
        if (empty($filters)) {
48
            return $sql;
49 1
        }
50
51
        $filter = implode(' AND ', $filters);
52 344
        return <<<SQL
53
        WITH USER_SQL AS ($sql), PAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)
54 344
        SELECT * FROM PAGINATION WHERE $filter
55
        SQL;
56
    }
57
58
    public function selectExists(string $rawSql): string
59
    {
60
        return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END FROM DUAL';
61
    }
62
63
    protected function defaultExpressionBuilders(): array
64
    {
65
        return array_merge(parent::defaultExpressionBuilders(), [
66
            InCondition::class => InConditionBuilder::class,
67
            LikeCondition::class => LikeConditionBuilder::class,
68
        ]);
69
    }
70
}
71