| Conditions | 10 |
| Paths | 30 |
| Total Lines | 45 |
| Code Lines | 24 |
| 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 |
||
| 50 | public function deleteSingle(array $identifiers, NZB $nzb, ReleaseImage $releaseImage): void |
||
| 51 | { |
||
| 52 | // Delete NZB from disk. |
||
| 53 | $nzbPath = $nzb->NZBPath($identifiers['g']); |
||
| 54 | if (! empty($nzbPath)) { |
||
| 55 | File::delete($nzbPath); |
||
| 56 | } |
||
| 57 | |||
| 58 | // Delete images. |
||
| 59 | $releaseImage->delete($identifiers['g']); |
||
| 60 | |||
| 61 | if (config('nntmux.elasticsearch_enabled') === true) { |
||
| 62 | if ($identifiers['i'] === false) { |
||
| 63 | $identifiers['i'] = Release::query()->where('guid', $identifiers['g'])->first(['id']); |
||
| 64 | if ($identifiers['i'] !== null) { |
||
| 65 | $identifiers['i'] = $identifiers['i']['id']; |
||
| 66 | } |
||
| 67 | } |
||
| 68 | if ($identifiers['i'] !== null) { |
||
| 69 | $params = [ |
||
| 70 | 'index' => 'releases', |
||
| 71 | 'id' => $identifiers['i'], |
||
| 72 | ]; |
||
| 73 | |||
| 74 | try { |
||
| 75 | Elasticsearch::delete($params); |
||
| 76 | } catch (Missing404Exception $e) { |
||
| 77 | // we do nothing here just catch the error, we don't care if release is missing from ES, we are deleting it anyway |
||
| 78 | } |
||
| 79 | } |
||
| 80 | } else { |
||
| 81 | // Delete from Manticore |
||
| 82 | if ($identifiers['i'] === false) { |
||
| 83 | $release = Release::query()->where('guid', $identifiers['g'])->first(['id']); |
||
| 84 | if ($release !== null) { |
||
| 85 | $identifiers['i'] = $release->id; |
||
| 86 | } |
||
| 87 | } |
||
| 88 | if (!empty($identifiers['i'])) { |
||
| 89 | $this->manticoreSearch->deleteRelease((int) $identifiers['i']); |
||
| 90 | } |
||
| 91 | } |
||
| 92 | |||
| 93 | // Delete from DB. |
||
| 94 | Release::whereGuid($identifiers['g'])->delete(); |
||
| 95 | } |
||
| 191 |