| Conditions | 12 |
| Paths | 91 |
| Total Lines | 82 |
| Code Lines | 50 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 6 | ||
| 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 |
||
| 138 | public function deleteSuperfluousVersions($object): int |
||
| 139 | { |
||
| 140 | $this->object = $object; |
||
| 141 | if (! $this->isValidObject()) { |
||
| 142 | return 0; |
||
| 143 | } |
||
| 144 | |||
| 145 | // array of version IDs to delete |
||
| 146 | // IMPORTANT |
||
| 147 | $this->toDelete[$this->getUniqueKey()] = []; |
||
| 148 | |||
| 149 | // Base table has Versioned data |
||
| 150 | $totalDeleted = 0; |
||
| 151 | |||
| 152 | $myTemplates = $this->findBestSuitedTemplates(); |
||
| 153 | foreach ($myTemplates as $className => $options) { |
||
| 154 | $runner = new $className($this->object, $this->toDelete[$this->getUniqueKey()]); |
||
| 155 | if ($this->verbose) { |
||
| 156 | DB::alteration_message('... ... ... Running ' . $runner->getTitle() . ': ' . $runner->getDescription()); |
||
| 157 | } |
||
| 158 | |||
| 159 | foreach ($options as $key => $value) { |
||
| 160 | $method = 'set' . $key; |
||
| 161 | $runner->{$method}($value); |
||
| 162 | } |
||
| 163 | |||
| 164 | $runner->run(); |
||
| 165 | $this->toDelete[$this->getUniqueKey()] = $runner->getToDelete(); |
||
| 166 | |||
| 167 | if ($this->verbose) { |
||
| 168 | DB::alteration_message('... ... ... total versions to delete now ' . count($this->toDelete[$this->getUniqueKey()])); |
||
| 169 | } |
||
| 170 | } |
||
| 171 | |||
| 172 | if (! count($this->toDelete[$this->getUniqueKey()])) { |
||
| 173 | return 0; |
||
| 174 | } |
||
| 175 | |||
| 176 | // Ugly (borrowed from DataObject::class), but returns all |
||
| 177 | // database tables relating to DataObject |
||
| 178 | $queriedTables = $this->getTablesForClassName(); |
||
| 179 | foreach ($queriedTables as $table) { |
||
| 180 | $overallCount = $this->countPerTableRegister[$table] ?? -1; |
||
| 181 | if($overallCount === -1) { |
||
| 182 | $selectOverallCountSQL = ' |
||
| 183 | SELECT COUNT(ID) AS C FROM "' . $table . '_Versions"'; |
||
| 184 | $overallCount = DB::query($selectOverallCountSQL)->value(); |
||
| 185 | } |
||
| 186 | if (true === $this->dryRun) { |
||
| 187 | $selectToBeDeletedSQL = ' |
||
| 188 | SELECT COUNT(ID) AS C FROM "' . $table . '_Versions" |
||
| 189 | WHERE |
||
| 190 | "Version" IN (' . implode(',', $this->toDelete[$this->getUniqueKey()]) . ') |
||
| 191 | AND "RecordID" = ' . (int) $this->object->ID; |
||
| 192 | |||
| 193 | $toBeDeletedCount = DB::query($selectToBeDeletedSQL)->value(); |
||
| 194 | $totalDeleted += $toBeDeletedCount; |
||
| 195 | if ($this->verbose) { |
||
| 196 | DB::alteration_message('... ... ... running ' . $select); |
||
| 197 | DB::alteration_message('... ... ... total rows to be deleted ... ' . $toBeDeletedCount . ' of ' . $overallCount); |
||
| 198 | } |
||
| 199 | } else { |
||
| 200 | $delSQL = ' |
||
| 201 | DELETE FROM "' . $table . '_Versions" |
||
| 202 | WHERE |
||
| 203 | "Version" IN (' . implode(',', $this->toDelete[$this->getUniqueKey()]) . ') |
||
| 204 | AND "RecordID" = ' . (int) $this->object->ID; |
||
| 205 | |||
| 206 | DB::query($delSQL); |
||
| 207 | $count = DB::affected_rows(); |
||
| 208 | $totalDeleted += $count; |
||
| 209 | $overallCount -= $count; |
||
| 210 | if ($this->verbose) { |
||
| 211 | DB::alteration_message('... ... ... running ' . $delSQL); |
||
| 212 | DB::alteration_message('... ... ... total rows deleted ... ' . $totalDeleted); |
||
| 213 | } |
||
| 214 | } |
||
| 215 | |||
| 216 | $this->addCountRegister($table, $overallCount); |
||
| 217 | } |
||
| 218 | |||
| 219 | return $totalDeleted; |
||
| 220 | } |
||
| 346 |
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