Passed
Pull Request — master (#146)
by Wilmer
02:37
created

Quoter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
eloc 9
c 3
b 0
f 0
dl 0
loc 26
ccs 0
cts 8
cp 0
rs 10
wmc 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 7 1
A quoteValue() 0 11 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mysql;
6
7
use PDO;
8
use Yiisoft\Db\Schema\Quoter as BaseQuoter;
9
10
/**
11
 * @todo Remove or use? Where is question
12
 * Temporary not used. Need add more tests for many charset
13
 */
14
final class Quoter extends BaseQuoter
15
{
16
    /**
17
     * @psalm-param string[]|string $columnQuoteCharacter
18
     * @psalm-param string[]|string $tableQuoteCharacter
19
     */
20
    public function __construct(
21
        array|string $columnQuoteCharacter,
22
        array|string $tableQuoteCharacter,
23
        string $tablePrefix = '',
24
        protected PDO|null $pdo = null
25
    ) {
26
        parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix, $pdo);
27
    }
28
29
    public function quoteValue(mixed $value): mixed
30
    {
31
        if (!is_string($value)) {
32
            return $value;
33
        }
34
35
        return "'" . str_replace(
36
            ['\\', "\x00", "\n", "\r", "'", '"', "\x1a"],
37
            ['\\\\', '\\0', '\\n', '\\r', "\'", '\"', '\\Z'],
38
            $value
39
        ) . "'";
40
    }
41
}
42