Passed
Pull Request — master (#133)
by Wilmer
04:36
created

LikeConditionBuilder::getEscapeSql()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2.0625

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 3
c 1
b 0
f 0
dl 0
loc 7
ccs 3
cts 4
cp 0.75
rs 10
cc 2
nc 2
nop 0
crap 2.0625
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Sqlite\Builder;
6
7
use Yiisoft\Db\QueryBuilder\Conditions\Builder\LikeConditionBuilder as BaseLikeConditionBuilder;
8
use Yiisoft\Db\QueryBuilder\QueryBuilderInterface;
9
10
final class LikeConditionBuilder extends BaseLikeConditionBuilder
11
{
12
    private string|null $escapeCharacter = '\\';
13
14 31
    public function __construct(QueryBuilderInterface $queryBuilder)
15
    {
16 31
        parent::__construct($queryBuilder, $this->getEscapeSql());
0 ignored issues
show
Unused Code introduced by
The call to Yiisoft\Db\QueryBuilder\...nBuilder::__construct() has too many arguments starting with $this->getEscapeSql(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

16
        parent::/** @scrutinizer ignore-call */ 
17
                __construct($queryBuilder, $this->getEscapeSql());

This check compares calls to functions or methods with their respective definitions. If the call has more arguments than are defined, it raises an issue.

If a function is defined several times with a different number of parameters, the check may pick up the wrong definition and report false positives. One codebase where this has been known to happen is Wordpress. Please note the @ignore annotation hint above.

Loading history...
17
    }
18
19
    /**
20
     * @return string character used to escape special characters in LIKE conditions.
21
     * By default, it's assumed to be `\`.
22
     */
23 31
    private function getEscapeSql(): string
24
    {
25 31
        if ($this->escapeCharacter !== null) {
26 31
            return " ESCAPE '{$this->escapeCharacter}'";
27
        }
28
29
        return '';
30
    }
31
}
32