Passed
Pull Request — master (#147)
by Wilmer
03:10
created

Quoter   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 0 Features 0
Metric Value
eloc 9
c 4
b 0
f 0
dl 0
loc 26
ccs 8
cts 8
cp 1
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 386
    public function __construct(
21
        array|string $columnQuoteCharacter,
22
        array|string $tableQuoteCharacter,
23
        string $tablePrefix = '',
24
        protected PDO|null $pdo = null
25
    ) {
26 386
        parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix, $pdo);
27
    }
28
29 149
    public function quoteValue(mixed $value): mixed
30
    {
31 149
        if (!is_string($value)) {
32 1
            return $value;
33
        }
34
35 149
        return "'" . str_replace(
36 149
            ['\\', "\x00", "\n", "\r", "'", '"', "\x1a"],
37 149
            ['\\\\', '\\0', '\\n', '\\r', "\'", '\"', '\\Z'],
38
            $value
39
        ) . "'";
40
    }
41
}
42