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

Quoter   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 9
c 1
b 0
f 0
dl 0
loc 33
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A quoteColumnName() 0 7 2
A __construct() 0 6 1
A getTableNameParts() 0 10 3
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