Total Complexity | 5 |
Total Lines | 36 |
Duplicated Lines | 0 % |
Coverage | 94.74% |
Changes | 1 | ||
Bugs | 0 | Features | 0 |
1 | <?php |
||
13 | final class Command extends AbstractPdoCommand |
||
14 | { |
||
15 | 6 | public function insertWithReturningPks(string $table, array $columns): bool|array |
|
16 | { |
||
17 | 6 | $params = []; |
|
18 | 6 | $sql = $this->db->getQueryBuilder()->insert($table, $columns, $params); |
|
19 | 6 | $this->setSql($sql)->bindValues($params); |
|
20 | |||
21 | 6 | if (!$this->execute()) { |
|
22 | return false; |
||
23 | } |
||
24 | |||
25 | 6 | $tableSchema = $this->db->getSchema()->getTableSchema($table); |
|
26 | 6 | $tablePrimaryKeys = $tableSchema?->getPrimaryKey() ?? []; |
|
27 | 6 | $result = []; |
|
28 | |||
29 | 6 | foreach ($tablePrimaryKeys as $name) { |
|
30 | 6 | if ($tableSchema?->getColumn($name)?->isAutoIncrement()) { |
|
31 | 5 | $result[$name] = $this->db->getLastInsertID((string) $tableSchema?->getSequenceName()); |
|
32 | 5 | continue; |
|
33 | } |
||
34 | |||
35 | /** @psalm-var mixed */ |
||
36 | 1 | $result[$name] = $columns[$name] ?? $tableSchema?->getColumn($name)?->getDefaultValue(); |
|
37 | } |
||
38 | |||
39 | 6 | return $result; |
|
40 | } |
||
41 | |||
42 | 1 | public function showDatabases(): array |
|
49 | } |
||
50 | } |
||
51 |