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

Command::insertWithReturningPks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 4.125

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 11
ccs 3
cts 6
cp 0.5
crap 4.125
rs 10
c 0
b 0
f 0
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