Conditions | 11 |
Paths | 2 |
Total Lines | 90 |
Code Lines | 61 |
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 |
||
23 | public function deleteFinishedAndOrphans(bool $echoCLI): int |
||
24 | { |
||
25 | $startTime = now()->toImmutable(); |
||
26 | $deletedCount = 0; |
||
27 | |||
28 | if ($echoCLI) { |
||
29 | echo $this->colorCLI->header('Process Releases -> Delete finished collections.'.PHP_EOL). |
||
30 | $this->colorCLI->primary(sprintf( |
||
31 | 'Deleting collections/binaries/parts older than %d hours.', |
||
32 | Settings::settingValue('partretentionhours') |
||
33 | ), true); |
||
34 | } |
||
35 | |||
36 | DB::transaction(function () use (&$deletedCount, $startTime, $echoCLI) { |
||
37 | $deleted = 0; |
||
38 | $deleteQuery = Collection::query() |
||
39 | ->where('dateadded', '<', now()->subHours(Settings::settingValue('partretentionhours'))) |
||
40 | ->delete(); |
||
41 | if ($deleteQuery > 0) { |
||
42 | $deleted = $deleteQuery; |
||
43 | $deletedCount += $deleted; |
||
44 | } |
||
45 | $firstQuery = $fourthQuery = now(); |
||
46 | |||
47 | $totalTime = $firstQuery->diffInSeconds($startTime, true); |
||
48 | |||
49 | if ($echoCLI) { |
||
50 | $this->colorCLI->primary( |
||
51 | 'Finished deleting '.$deleted.' old collections/binaries/parts in '. |
||
52 | $totalTime.Str::plural(' second', $totalTime), |
||
53 | true |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | if (random_int(0, 200) <= 1) { |
||
58 | if ($echoCLI) { |
||
59 | echo $this->colorCLI->header('Process Releases -> Remove CBP orphans.'.PHP_EOL). |
||
60 | $this->colorCLI->primary('Deleting orphaned collections.'); |
||
61 | } |
||
62 | |||
63 | $deleted = 0; |
||
64 | $deleteQuery = Collection::query() |
||
65 | ->whereNull('binaries.id') |
||
66 | ->orWhereNull('parts.binaries_id') |
||
67 | ->leftJoin('binaries', 'collections.id', '=', 'binaries.collections_id') |
||
68 | ->leftJoin('parts', 'binaries.id', '=', 'parts.binaries_id') |
||
69 | ->delete(); |
||
70 | |||
71 | if ($deleteQuery > 0) { |
||
72 | $deleted = $deleteQuery; |
||
73 | $deletedCount += $deleted; |
||
74 | } |
||
75 | |||
76 | $totalTime = now()->diffInSeconds($firstQuery); |
||
77 | |||
78 | if ($echoCLI) { |
||
79 | $this->colorCLI->primary('Finished deleting '.$deleted.' orphaned collections in '.$totalTime.Str::plural(' second', $totalTime), true); |
||
80 | } |
||
81 | } |
||
82 | |||
83 | if ($echoCLI) { |
||
84 | $this->colorCLI->primary('Deleting collections that were missed after NZB creation.', true); |
||
85 | } |
||
86 | |||
87 | $deleted = 0; |
||
88 | $collections = Collection::query() |
||
89 | ->where('releases.nzbstatus', '=', 1) |
||
90 | ->leftJoin('releases', 'releases.id', '=', 'collections.releases_id') |
||
91 | ->select('collections.id') |
||
92 | ->get(); |
||
93 | |||
94 | foreach ($collections as $collection) { |
||
95 | $deleted++; |
||
96 | Collection::query()->where('id', $collection->id)->delete(); |
||
97 | } |
||
98 | $deletedCount += $deleted; |
||
99 | |||
100 | $colDelTime = now()->diffInSeconds($fourthQuery, true); |
||
101 | $totalTime = $fourthQuery->diffInSeconds($startTime, true); |
||
102 | |||
103 | if ($echoCLI) { |
||
104 | $this->colorCLI->primary( |
||
105 | 'Finished deleting '.$deleted.' collections missed after NZB creation in '.$colDelTime.Str::plural(' second', $colDelTime). |
||
106 | PHP_EOL.'Removed '.number_format($deletedCount).' parts/binaries/collection rows in '.$totalTime.Str::plural(' second', $totalTime), |
||
107 | true |
||
108 | ); |
||
109 | } |
||
110 | }, 10); |
||
111 | |||
112 | return $deletedCount; |
||
113 | } |
||
115 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.