Passed
Push — master ( 527670...666a8e )
by Sergei
06:51 queued 02:16
created

Command::insertWithReturningPks()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 11
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 5
CRAP Score 3.0416

Importance

Changes 0
Metric Value
cc 3
eloc 5
nc 3
nop 2
dl 0
loc 11
ccs 5
cts 6
cp 0.8333
crap 3.0416
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 10
    public function insertWithReturningPks(string $table, array $columns): bool|array
16
    {
17 10
        if (empty($this->db->getSchema()->getTableSchema($table)?->getPrimaryKey())) {
18 1
            if (parent::insert($table, $columns)->execute() === 0) {
19
                return false;
20
            }
21
22 1
            return [];
23
        }
24
25 9
        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