Passed
Branch master (e888a2)
by Wilmer
30:54 queued 17:34
created

Quoter::getTableNameParts()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 11
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 2.0185

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 7
c 1
b 0
f 0
nc 2
nop 1
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 2.0185
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
use Yiisoft\Db\Schema\QuoterInterface;
9
10
use function preg_match;
11
use function preg_match_all;
12
13
final class Quoter extends BaseQuoter implements QuoterInterface
14
{
15
    /**
16
     * @psalm-param string[] $columnQuoteCharacter
17
     * @psalm-param string[] $tableQuoteCharacter
18
     */
19 426
    public function __construct(
20
        array $columnQuoteCharacter,
21
        array $tableQuoteCharacter,
22
        string $tablePrefix = ''
23
    ) {
24 426
        parent::__construct($columnQuoteCharacter, $tableQuoteCharacter, $tablePrefix);
25
    }
26
27 214
    public function quoteColumnName(string $name): string
28
    {
29 214
        if (preg_match('/^\[.*]$/', $name)) {
30 29
            return $name;
31
        }
32
33 214
        return parent::quoteColumnName($name);
34
    }
35
36 205
    public function getTableNameParts(string $name): array
37
    {
38 205
        if (preg_match_all('/([^.\[\]]+)|\[([^\[\]]+)]/', $name, $matches)) {
39 205
            $parts = array_slice($matches[0], -4, 4);
40
        } else {
41
            $parts = [$name];
42
        }
43
44 205
        return array_map(function ($part) {
45 205
            return $this->unquoteSimpleTableName($part);
46
        }, $parts);
47
    }
48
}
49