| Conditions | 4 |
| Paths | 5 |
| Total Lines | 64 |
| Code Lines | 44 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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 |
||
| 93 | public function process() |
||
| 94 | { |
||
| 95 | $statusList = implode('\', \'', $this->config()->cleanup_statuses); |
||
| 96 | switch ($this->config()->cleanup_method) { |
||
| 97 | // If Age, we need to get jobs that are at least n days old |
||
| 98 | case "age": |
||
| 99 | $cutOff = date( |
||
| 100 | "Y-m-d H:i:s", |
||
| 101 | strtotime(DBDatetime::now() . |
||
| 102 | " - " . |
||
| 103 | $this->config()->cleanup_value . |
||
| 104 | " days") |
||
| 105 | ); |
||
| 106 | $stale = DB::query( |
||
| 107 | 'SELECT "ID" |
||
| 108 | FROM "QueuedJobDescriptor" |
||
| 109 | WHERE "JobStatus" |
||
| 110 | IN (\'' . $statusList . '\') |
||
| 111 | AND "LastEdited" < \'' . $cutOff .'\'' |
||
| 112 | ); |
||
| 113 | $staleJobs = $stale->column("ID"); |
||
| 114 | break; |
||
| 115 | // If Number, we need to save n records, then delete from the rest |
||
| 116 | case "number": |
||
| 117 | $fresh = DB::query( |
||
| 118 | 'SELECT "ID" |
||
| 119 | FROM "QueuedJobDescriptor" |
||
| 120 | ORDER BY "LastEdited" |
||
| 121 | ASC LIMIT ' . $this->config()->cleanup_value |
||
| 122 | ); |
||
| 123 | $freshJobIDs = implode('\', \'', $fresh->column("ID")); |
||
| 124 | |||
| 125 | $stale = DB::query( |
||
| 126 | 'SELECT "ID" |
||
| 127 | FROM "QueuedJobDescriptor" |
||
| 128 | WHERE "ID" |
||
| 129 | NOT IN (\'' . $freshJobIDs . '\') |
||
| 130 | AND "JobStatus" |
||
| 131 | IN (\'' . $statusList . '\')' |
||
| 132 | ); |
||
| 133 | $staleJobs = $stale->column("ID"); |
||
| 134 | break; |
||
| 135 | default: |
||
| 136 | $this->addMessage("Incorrect configuration values set. Cleanup ignored"); |
||
| 137 | $this->isComplete = true; |
||
| 138 | return; |
||
| 139 | } |
||
| 140 | if (empty($staleJobs)) { |
||
| 141 | $this->addMessage("No jobs to clean up."); |
||
| 142 | $this->isComplete = true; |
||
| 143 | $this->reenqueue(); |
||
| 144 | return; |
||
| 145 | } |
||
| 146 | $numJobs = count($staleJobs); |
||
| 147 | $staleJobs = implode('\', \'', $staleJobs); |
||
| 148 | DB::query('DELETE FROM "QueuedJobDescriptor" |
||
| 149 | WHERE "ID" |
||
| 150 | IN (\'' . $staleJobs . '\')'); |
||
| 151 | $this->addMessage($numJobs . " jobs cleaned up."); |
||
| 152 | // let's make sure there is a cleanupJob in the queue |
||
| 153 | $this->reenqueue(); |
||
| 154 | $this->isComplete = true; |
||
| 155 | return; |
||
| 156 | } |
||
| 157 | |||
| 168 |
This check marks private properties in classes that are never used. Those properties can be removed.