| Total Complexity | 4 |
| Total Lines | 55 |
| Duplicated Lines | 0 % |
| Changes | 0 | ||
| 1 | <?php declare(strict_types=1); |
||
| 7 | trait OnDuplicateKeyUpdateTrait |
||
| 8 | { |
||
| 9 | /** |
||
| 10 | * @var array |
||
| 11 | */ |
||
| 12 | protected $onDuplicateKeyUpdate = []; |
||
| 13 | |||
| 14 | /** |
||
| 15 | * @param string $column |
||
| 16 | * @param null|int|string|double $value |
||
| 17 | * |
||
| 18 | * @throws QueryBuilderException |
||
| 19 | * @return $this |
||
| 20 | */ |
||
| 21 | public function onDuplicateKeyUpdate(string $column, $value) |
||
| 22 | { |
||
| 23 | if (empty($column)) { |
||
| 24 | throw new QueryBuilderException('You must pass $column to onDuplicateKeyUpdate function!'); |
||
| 25 | } |
||
| 26 | |||
| 27 | $columnNormalised = \sprintf( |
||
| 28 | '%s_OnDuplicateKeyUpdate', |
||
| 29 | \implode( |
||
| 30 | '_', |
||
| 31 | \array_map( |
||
| 32 | function ($columnPart) { |
||
| 33 | return \mb_convert_case($columnPart, MB_CASE_TITLE); |
||
| 34 | }, |
||
| 35 | \explode('.', $column) |
||
| 36 | ) |
||
| 37 | ) |
||
| 38 | ); |
||
| 39 | |||
| 40 | $this->onDuplicateKeyUpdate = \array_merge( |
||
| 41 | $this->onDuplicateKeyUpdate, |
||
| 42 | [ |
||
| 43 | $column => \sprintf('%s = :%s', $column, $columnNormalised), |
||
| 44 | ] |
||
| 45 | ); |
||
| 46 | |||
| 47 | $this->bindValue([ |
||
|
|
|||
| 48 | $columnNormalised => $value, |
||
| 49 | ]); |
||
| 50 | |||
| 51 | return $this; |
||
| 52 | } |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @return null|string |
||
| 56 | */ |
||
| 57 | protected function buildOnDuplicateKeyUpdateQueryPart(): ?string |
||
| 62 | ; |
||
| 63 | } |
||
| 65 |