| Conditions | 11 |
| Paths | 55 |
| Total Lines | 74 |
| Code Lines | 41 |
| 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 |
||
| 79 | public function upsert( |
||
| 80 | string $table, |
||
| 81 | Query|array $insertColumns, |
||
| 82 | bool|array $updateColumns, |
||
| 83 | array &$params = [] |
||
| 84 | ): string { |
||
| 85 | /** @var Constraint[] $constraints */ |
||
| 86 | $constraints = []; |
||
| 87 | [$uniqueNames, $insertNames, $updateNames] = $this->queryBuilder->prepareUpsertColumns( |
||
| 88 | $table, |
||
| 89 | $insertColumns, |
||
| 90 | $updateColumns, |
||
| 91 | $constraints |
||
| 92 | ); |
||
| 93 | |||
| 94 | if (empty($uniqueNames)) { |
||
| 95 | return $this->insert($table, $insertColumns, $params); |
||
| 96 | } |
||
| 97 | |||
| 98 | $onCondition = ['or']; |
||
| 99 | $quotedTableName = $this->queryBuilder->quoter()->quoteTableName($table); |
||
| 100 | |||
| 101 | foreach ($constraints as $constraint) { |
||
| 102 | $constraintCondition = ['and']; |
||
| 103 | |||
| 104 | foreach ($constraint->getColumnNames() as $name) { |
||
| 105 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 106 | $constraintCondition[] = "$quotedTableName.$quotedName=[EXCLUDED].$quotedName"; |
||
| 107 | } |
||
| 108 | |||
| 109 | $onCondition[] = $constraintCondition; |
||
| 110 | } |
||
| 111 | |||
| 112 | $on = $this->queryBuilder->buildCondition($onCondition, $params); |
||
| 113 | [, $placeholders, $values, $params] = $this->queryBuilder->prepareInsertValues($table, $insertColumns, $params); |
||
| 114 | $mergeSql = 'MERGE ' . $this->queryBuilder->quoter()->quoteTableName($table) . ' WITH (HOLDLOCK) ' |
||
| 115 | . 'USING (' . (!empty($placeholders) |
||
| 116 | ? 'VALUES (' . implode(', ', $placeholders) . ')' |
||
| 117 | : ltrim($values, ' ')) . ') AS [EXCLUDED] (' . implode(', ', $insertNames) . ') ' . "ON ($on)"; |
||
| 118 | $insertValues = []; |
||
| 119 | |||
| 120 | foreach ($insertNames as $name) { |
||
| 121 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 122 | |||
| 123 | if (strrpos($quotedName, '.') === false) { |
||
| 124 | $quotedName = '[EXCLUDED].' . $quotedName; |
||
| 125 | } |
||
| 126 | |||
| 127 | $insertValues[] = $quotedName; |
||
| 128 | } |
||
| 129 | |||
| 130 | $insertSql = 'INSERT (' . implode(', ', $insertNames) . ')' . ' VALUES (' . implode(', ', $insertValues) . ')'; |
||
| 131 | |||
| 132 | if ($updateColumns === false) { |
||
| 133 | return "$mergeSql WHEN NOT MATCHED THEN $insertSql;"; |
||
| 134 | } |
||
| 135 | |||
| 136 | if ($updateColumns === true) { |
||
| 137 | $updateColumns = []; |
||
| 138 | |||
| 139 | foreach ($updateNames as $name) { |
||
| 140 | $quotedName = $this->queryBuilder->quoter()->quoteColumnName($name); |
||
| 141 | if (strrpos($quotedName, '.') === false) { |
||
| 142 | $quotedName = '[EXCLUDED].' . $quotedName; |
||
| 143 | } |
||
| 144 | |||
| 145 | $updateColumns[$name] = new Expression($quotedName); |
||
| 146 | } |
||
| 147 | } |
||
| 148 | |||
| 149 | [$updates, $params] = $this->queryBuilder->prepareUpdateSets($table, $updateColumns, $params); |
||
| 150 | $updateSql = 'UPDATE SET ' . implode(', ', $updates); |
||
| 151 | |||
| 152 | return "$mergeSql WHEN MATCHED THEN $updateSql WHEN NOT MATCHED THEN $insertSql;"; |
||
| 153 | } |
||
| 155 |
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