| Conditions | 14 |
| Paths | 58 |
| Total Lines | 84 |
| Code Lines | 48 |
| 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 |
||
| 132 | public function deleteSuperfluousVersions($object, ?bool $verbose = false): int |
||
| 133 | { |
||
| 134 | $this->object = $object; |
||
| 135 | $this->verbose = $verbose; |
||
| 136 | if (false === $this->hasStages()) { |
||
| 137 | if ($this->verbose) { |
||
| 138 | DB::alteration_message('... ... ... Error, no stages', 'deleted'); |
||
| 139 | } |
||
| 140 | |||
| 141 | return 0; |
||
| 142 | } |
||
| 143 | |||
| 144 | if (false === $this->object->isLiveVersion()) { |
||
| 145 | if ($this->verbose) { |
||
| 146 | DB::alteration_message('... ... ... Error, not a live version', 'deleted'); |
||
| 147 | } |
||
| 148 | |||
| 149 | return 0; |
||
| 150 | } |
||
| 151 | |||
| 152 | // array of version IDs to delete |
||
| 153 | // IMPORTANT |
||
| 154 | $this->toDelete[$this->getUniqueKey()] = []; |
||
| 155 | |||
| 156 | // Base table has Versioned data |
||
| 157 | $totalDeleted = 0; |
||
| 158 | |||
| 159 | $myTemplates = $this->findBestSuitedTemplates(); |
||
| 160 | foreach ($myTemplates as $className => $options) { |
||
| 161 | $runner = new $className($this->object, $this->toDelete[$this->getUniqueKey()]); |
||
| 162 | if ($this->verbose) { |
||
| 163 | DB::alteration_message('... ... ... Running ' . $runner->getTitle() . ': ' . $runner->getDescription()); |
||
| 164 | } |
||
| 165 | |||
| 166 | foreach ($options as $key => $value) { |
||
| 167 | $method = 'set' . $key; |
||
| 168 | $runner->{$method}($value); |
||
| 169 | } |
||
| 170 | |||
| 171 | $runner->run(); |
||
| 172 | $this->toDelete[$this->getUniqueKey()] = $runner->getToDelete(); |
||
| 173 | |||
| 174 | if ($this->verbose) { |
||
| 175 | DB::alteration_message('... ... ... total versions to delete now ' . count($this->toDelete[$this->getUniqueKey()])); |
||
| 176 | } |
||
| 177 | } |
||
| 178 | |||
| 179 | if (! count($this->toDelete[$this->getUniqueKey()])) { |
||
| 180 | return 0; |
||
| 181 | } |
||
| 182 | |||
| 183 | // Ugly (borrowed from DataObject::class), but returns all |
||
| 184 | // database tables relating to DataObject |
||
| 185 | $queriedTables = $this->getTablesForClassName(); |
||
| 186 | foreach ($queriedTables as $table) { |
||
| 187 | if($this->dryRun === true) { |
||
| 188 | $select = ' |
||
| 189 | SELECT COUNT(ID) AS C FROM "' . $table . '_Versions" |
||
| 190 | WHERE |
||
| 191 | "Version" IN (' . implode(',', $this->toDelete[$this->getUniqueKey()]) . ') |
||
| 192 | AND "RecordID" = ' . (int) $this->object->ID; |
||
| 193 | |||
| 194 | $value = DB::query($select)->value(); |
||
| 195 | if ($this->verbose) { |
||
| 196 | DB::alteration_message('... ... ... running ' . $select); |
||
| 197 | DB::alteration_message('... ... ... total rows to be deleted ... ' . $value); |
||
| 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 | $totalDeleted += DB::affected_rows(); |
||
| 208 | if ($this->verbose) { |
||
| 209 | DB::alteration_message('... ... ... running ' . $delSQL); |
||
| 210 | DB::alteration_message('... ... ... total rows deleted ... ' . $totalDeleted); |
||
| 211 | } |
||
| 212 | } |
||
| 213 | } |
||
| 214 | |||
| 215 | return $totalDeleted; |
||
| 216 | } |
||
| 274 |
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