| 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 |
||
| 49 | public function upsert(string $table, Query|array $insertColumns, bool|array $updateColumns, array &$params): string |
||
| 50 | { |
||
| 51 | /** @var Constraint[] $constraints */ |
||
| 52 | $constraints = []; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * @psalm-var array<array-key, string> $insertNames |
||
| 56 | * @psalm-var array<array-key, string> $updateNames |
||
| 57 | * @psalm-var array<string, ExpressionInterface|string>|bool $updateColumns |
||
| 58 | */ |
||
| 59 | [$uniqueNames, $insertNames, $updateNames] = $this->queryBuilder->prepareUpsertColumns( |
||
| 60 | $table, |
||
| 61 | $insertColumns, |
||
| 62 | $updateColumns, |
||
| 63 | $constraints |
||
| 64 | ); |
||
| 65 | |||
| 66 | if (empty($uniqueNames)) { |
||
| 67 | return $this->insert($table, $insertColumns, $params); |
||
| 68 | } |
||
| 69 | |||
| 70 | /** |
||
| 71 | * @psalm-var array<array-key, string> $placeholders |
||
| 72 | */ |
||
| 73 | [, $placeholders, $values, $params] = $this->queryBuilder->prepareInsertValues($table, $insertColumns, $params); |
||
| 74 | |||
| 75 | $insertSql = 'INSERT OR IGNORE INTO ' |
||
| 76 | . $this->queryBuilder->quoter()->quoteTableName($table) |
||
| 77 | . (!empty($insertNames) ? ' (' . implode(', ', $insertNames) . ')' : '') |
||
| 78 | . (!empty($placeholders) ? ' VALUES (' . implode(', ', $placeholders) . ')' : "$values"); |
||
| 79 | |||
| 80 | if ($updateColumns === false) { |
||
| 81 | return $insertSql; |
||
| 82 | } |
||
| 83 | |||
| 84 | $updateCondition = ['or']; |
||
| 85 | $quotedTableName = $this->queryBuilder->quoter()->quoteTableName($table); |
||
| 86 | |||
| 87 | foreach ($constraints as $constraint) { |
||
| 88 | $constraintCondition = ['and']; |
||
| 89 | /** @psalm-var array<array-key, string> */ |
||
| 90 | $columnsNames = $constraint->getColumnNames(); |
||
| 91 | foreach ($columnsNames as $name) { |
||
| 92 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 93 | $constraintCondition[] = "$quotedTableName.$quotedName=(SELECT $quotedName FROM `EXCLUDED`)"; |
||
| 94 | } |
||
| 95 | $updateCondition[] = $constraintCondition; |
||
| 96 | } |
||
| 97 | |||
| 98 | if ($updateColumns === true) { |
||
| 99 | $updateColumns = []; |
||
| 100 | foreach ($updateNames as $name) { |
||
| 101 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 102 | |||
| 103 | if (strrpos($quotedName, '.') === false) { |
||
| 104 | $quotedName = "(SELECT $quotedName FROM `EXCLUDED`)"; |
||
| 105 | } |
||
| 106 | $updateColumns[$name] = new Expression($quotedName); |
||
| 107 | } |
||
| 108 | } |
||
| 109 | |||
| 110 | $updateSql = 'WITH "EXCLUDED" (' |
||
| 111 | . implode(', ', $insertNames) |
||
| 112 | . ') AS (' . (!empty($placeholders) |
||
| 113 | ? 'VALUES (' . implode(', ', $placeholders) . ')' |
||
| 114 | : ltrim("$values", ' ')) . ') ' . $this->update($table, $updateColumns, $updateCondition, $params); |
||
| 115 | |||
| 116 | return "$updateSql; $insertSql;"; |
||
| 117 | } |
||
| 119 |
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