Conditions | 4 |
Paths | 4 |
Total Lines | 25 |
Code Lines | 14 |
Lines | 0 |
Ratio | 0 % |
Tests | 14 |
CRAP Score | 4.0047 |
Changes | 0 |
1 | <?php |
||
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 | } |
||
51 |