| Conditions | 11 |
| Paths | 53 |
| Total Lines | 68 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 57 | public function upsert(string $table, Query|array $insertColumns, bool|array $updateColumns, array &$params): string |
||
| 58 | { |
||
| 59 | /** @var Constraint[] $constraints */ |
||
| 60 | $constraints = []; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * @psalm-var array<array-key, string> $insertNames |
||
| 64 | * @psalm-var array<array-key, string> $updateNames |
||
| 65 | * @psalm-var array<string, ExpressionInterface|string>|bool $updateColumns |
||
| 66 | */ |
||
| 67 | [$uniqueNames, $insertNames, $updateNames] = $this->queryBuilder->prepareUpsertColumns( |
||
| 68 | $table, |
||
| 69 | $insertColumns, |
||
| 70 | $updateColumns, |
||
| 71 | $constraints |
||
| 72 | ); |
||
| 73 | |||
| 74 | if (empty($uniqueNames)) { |
||
| 75 | return $this->insert($table, $insertColumns, $params); |
||
| 76 | } |
||
| 77 | |||
| 78 | /** |
||
| 79 | * @psalm-var array<array-key, string> $placeholders |
||
| 80 | */ |
||
| 81 | [, $placeholders, $values, $params] = $this->queryBuilder->prepareInsertValues($table, $insertColumns, $params); |
||
| 82 | |||
| 83 | $insertSql = 'INSERT OR IGNORE INTO ' |
||
| 84 | . $this->queryBuilder->quoter()->quoteTableName($table) |
||
| 85 | . (!empty($insertNames) ? ' (' . implode(', ', $insertNames) . ')' : '') |
||
| 86 | . (!empty($placeholders) ? ' VALUES (' . implode(', ', $placeholders) . ')' : "$values"); |
||
| 87 | |||
| 88 | if ($updateColumns === false) { |
||
| 89 | return $insertSql; |
||
| 90 | } |
||
| 91 | |||
| 92 | $updateCondition = ['or']; |
||
| 93 | $quotedTableName = $this->queryBuilder->quoter()->quoteTableName($table); |
||
| 94 | |||
| 95 | foreach ($constraints as $constraint) { |
||
| 96 | $constraintCondition = ['and']; |
||
| 97 | /** @psalm-var array<array-key, string> */ |
||
| 98 | $columnsNames = $constraint->getColumnNames(); |
||
| 99 | foreach ($columnsNames as $name) { |
||
| 100 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 101 | $constraintCondition[] = "$quotedTableName.$quotedName=(SELECT $quotedName FROM `EXCLUDED`)"; |
||
| 102 | } |
||
| 103 | $updateCondition[] = $constraintCondition; |
||
| 104 | } |
||
| 105 | |||
| 106 | if ($updateColumns === true) { |
||
| 107 | $updateColumns = []; |
||
| 108 | foreach ($updateNames as $name) { |
||
| 109 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 110 | |||
| 111 | if (strrpos($quotedName, '.') === false) { |
||
| 112 | $quotedName = "(SELECT $quotedName FROM `EXCLUDED`)"; |
||
| 113 | } |
||
| 114 | $updateColumns[$name] = new Expression($quotedName); |
||
| 115 | } |
||
| 116 | } |
||
| 117 | |||
| 118 | $updateSql = 'WITH "EXCLUDED" (' |
||
| 119 | . implode(', ', $insertNames) |
||
| 120 | . ') AS (' . (!empty($placeholders) |
||
| 121 | ? 'VALUES (' . implode(', ', $placeholders) . ')' |
||
| 122 | : ltrim("$values", ' ')) . ') ' . $this->update($table, $updateColumns, $updateCondition, $params); |
||
| 123 | |||
| 124 | return "$updateSql; $insertSql;"; |
||
| 125 | } |
||
| 127 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths