Passed
Pull Request — dev (#52)
by Wilmer
09:20
created

LikeConditionBuilder   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 33
ccs 6
cts 6
cp 1
rs 10
c 0
b 0
f 0
wmc 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Oracle\Builder;
6
7
use Exception;
8
use Yiisoft\Db\Query\Conditions\Builder\LikeConditionBuilder as AbstractLikeConditionBuilder;
9
use Yiisoft\Db\Query\Conditions\Interface\LikeConditionInterface;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_INTERFACE, expecting T_STRING or '{' on line 9 at column 32
Loading history...
10
use Yiisoft\Db\Query\QueryBuilderInterface;
11
use Yiisoft\Db\Schema\Quoter;
12
13
use function substr;
14
15
final class LikeConditionBuilder extends AbstractLikeConditionBuilder
16
{
17
    protected ?string $escapeCharacter = '!';
18
19
    /**
20
     * `\` is initialized in {@see buildLikeCondition()} method since we need to choose replacement value based on
21
     * {@see Quoter::quoteValue()}.
22
     */
23
    protected array $escapingReplacements = [
24
        '%' => '!%',
25
        '_' => '!_',
26
        '!' => '!!',
27
    ];
28
29 31
    public function __construct(private QueryBuilderInterface $queryBuilder)
30
    {
31 31
        parent::__construct($queryBuilder);
32
    }
33
34
    /**
35
     * @throws Exception
36
     */
37 31
    public function build(LikeConditionInterface $expression, array &$params = []): string
38
    {
39 31
        if (!isset($this->escapingReplacements['\\'])) {
40
            /*
41
             * Different pdo_oci8 versions may or may not implement PDO::quote(), so {@see Quoter::quoteValue()} may or
42
             * may not quote \.
43
             */
44 31
            $this->escapingReplacements['\\'] = substr((string) $this->queryBuilder->quoter()->quoteValue('\\'), 1, -1);
45
        }
46
47 31
        return parent::build($expression, $params);
48
    }
49
}
50