Passed
Pull Request — master (#287)
by Sergei
13:55 queued 09:29
created

Command   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 22
Duplicated Lines 0 %

Test Coverage

Coverage 70%

Importance

Changes 0
Metric Value
eloc 10
dl 0
loc 22
ccs 7
cts 10
cp 0.7
rs 10
c 0
b 0
f 0
wmc 4

2 Methods

Rating   Name   Duplication   Size   Complexity  
A insertWithReturningPks() 0 11 3
A showDatabases() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Yiisoft\Db\Mssql;
6
7
use Yiisoft\Db\Driver\Pdo\AbstractPdoCommand;
8
9
/**
10
 * Implements a database command that can be executed against a PDO (PHP Data Object) database connection for MSSQL
11
 * Server.
12
 */
13
final class Command extends AbstractPdoCommand
14
{
15 8
    public function insertWithReturningPks(string $table, array $columns): bool|array
16
    {
17 8
        if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) {
18
            if (parent::insert($table, $columns)->execute() === 0) {
19
                return false;
20
            }
21
22
            return [];
23
        }
24
25 8
        return parent::insertWithReturningPks($table, $columns);
26
    }
27
28 1
    public function showDatabases(): array
29
    {
30 1
        $sql = <<<SQL
31
        SELECT [name] FROM [sys].[databases] WHERE [name] NOT IN ('master', 'tempdb', 'model', 'msdb')
32 1
        SQL;
33
34 1
        return $this->setSql($sql)->queryColumn();
35
    }
36
}
37