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