Passed
Push — dev ( 7ae04d...cd5ace )
by Def
30:02 queued 08:14
created

DQLQueryBuilder::selectExists()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
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
13
use function array_merge;
14
use function implode;
15
16
final class DQLQueryBuilder extends AbstractDQLQueryBuilder
17
{
18 166
    public function buildOrderByAndLimit(string $sql, array $orderBy, $limit, $offset, array &$params = []): string
19
    {
20 166
        $orderByString = $this->buildOrderBy($orderBy, $params);
21
22 166
        if ($orderByString !== '') {
23 6
            $sql .= $this->separator . $orderByString;
24
        }
25
26 166
        $filters = [];
27
28 166
        if ($this->hasOffset($offset)) {
29 1
            $filters[] = 'rowNumId > ' . (string) $offset;
30
        }
31
32 166
        if ($this->hasLimit($limit)) {
33 9
            $filters[] = 'rownum <= ' . (string) $limit;
34
        }
35
36 166
        if (empty($filters)) {
37 160
            return $sql;
38
        }
39
40 9
        $filter = implode(' AND ', $filters);
41
        return <<<SQL
42
        WITH USER_SQL AS ($sql), PAGINATION AS (SELECT USER_SQL.*, rownum as rowNumId FROM USER_SQL)
43
        SELECT * FROM PAGINATION WHERE $filter
44
        SQL;
45
    }
46
47 1
    public function selectExists(string $rawSql): string
48
    {
49 1
        return 'SELECT CASE WHEN EXISTS(' . $rawSql . ') THEN 1 ELSE 0 END FROM DUAL';
50
    }
51
52 344
    protected function defaultExpressionBuilders(): array
53
    {
54 344
        return array_merge(parent::defaultExpressionBuilders(), [
55
            InCondition::class => InConditionBuilder::class,
56
            LikeCondition::class => LikeConditionBuilder::class,
57
        ]);
58
    }
59
}
60