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

Quoter::getTableNameParts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2.032

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
nc 2
nop 1
dl 0
loc 9
ccs 4
cts 5
cp 0.8
crap 2.032
rs 10
c 2
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
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