Passed
Push — master ( 9b125d...f5b0c0 )
by Alexander
11:25 queued 07:35
created

Quoter::quoteColumnName()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 7
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 7
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Schema\Quoter as BaseQuoter;
8
use Yiisoft\Db\Schema\QuoterInterface;
9
10
use function preg_match;
11
use function preg_match_all;
12
use function str_replace;
13
14
final class Quoter extends BaseQuoter implements QuoterInterface
15
{
16
    /**
17
     * @psalm-param string[] $columnQuoteCharacter
18
     * @psalm-param string[] $tableQuoteCharacter
19
     */
20 407
    public function __construct(
21
        array $columnQuoteCharacter,
22
        array $tableQuoteCharacter,
23
        string $tablePrefix = ''
24
    ) {
25 407
        parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix);
26
    }
27
28 213
    public function quoteColumnName(string $name): string
29
    {
30 213
        if (preg_match('/^\[.*]$/', $name)) {
31 28
            return $name;
32
        }
33
34 213
        return parent::quoteColumnName($name);
35
    }
36
37 120
    protected function getTableNameParts(string $name): array
38
    {
39 120
        $parts = [$name];
40 120
        preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches);
41
42 120
        if (isset($matches[0]) && !empty($matches[0])) {
43 120
            $parts = $matches[0];
44
        }
45
46 120
        return str_replace(['[', ']'], '', $parts);
47
    }
48
}
49