Quoter::getTableNameParts()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 2
eloc 5
c 2
b 0
f 0
nc 2
nop 2
dl 0
loc 9
ccs 5
cts 5
cp 1
crap 2
rs 10
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
/**
13
 * Implements the MSSQL Server quoting and unquoting methods.
14
 */
15
final class Quoter extends BaseQuoter
16
{
17 581
    public function quoteColumnName(string $name): string
18
    {
19 581
        if (preg_match('/^\[.*]$/', $name)) {
20 9
            return $name;
21
        }
22
23 579
        return parent::quoteColumnName($name);
24
    }
25
26 591
    public function getTableNameParts(string $name, bool $withColumn = false): array
27
    {
28 591
        if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches) > 0) {
29 589
            $parts = array_slice($matches[0], -4, 4);
30
        } else {
31 2
            $parts = [$name];
32
        }
33
34 591
        return $this->unquoteParts($parts, $withColumn);
35
    }
36
}
37