Passed
Pull Request — master (#117)
by Wilmer
04:12
created

Quoter   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
eloc 8
dl 0
loc 20
ccs 8
cts 9
cp 0.8889
rs 10
c 2
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A quoteColumnName() 0 7 2
A getTableNameParts() 0 9 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Schema\Quoter as BaseQuoter;
8
9
use function preg_match;
10
use function preg_match_all;
11
12
final class Quoter extends BaseQuoter
13
{
14 217
    public function quoteColumnName(string $name): string
15
    {
16 217
        if (preg_match('/^\[.*]$/', $name)) {
17 30
            return $name;
18
        }
19
20 217
        return parent::quoteColumnName($name);
21
    }
22
23 207
    public function getTableNameParts(string $name): array
24
    {
25 207
        if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches)) {
26 207
            $parts = array_slice($matches[0], -4, 4);
27
        } else {
28
            $parts = [$name];
29
        }
30
31 207
        return array_map(fn ($part) => $this->unquoteSimpleTableName($part), $parts);
32
    }
33
}
34