| Conditions | 5 | 
| Paths | 7 | 
| Total Lines | 68 | 
| Code Lines | 47 | 
| 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 | return; | ||
| 144 | } | ||
| 145 | $numJobs = count($staleJobs); | ||
| 146 |         $staleJobs = implode('\', \'', $staleJobs); | ||
| 147 |         DB::query('DELETE FROM "QueuedJobDescriptor" | ||
| 148 | WHERE "ID" | ||
| 149 | IN (\'' . $staleJobs . '\')'); | ||
| 150 | $this->addMessage($numJobs . " jobs cleaned up."); | ||
| 151 | // let's make sure there is a cleanupJob in the queue | ||
| 152 |         if (Config::inst()->get('SilverStripe\\QueuedJobs\\Jobs\\CleanupJob', 'is_enabled')) { | ||
| 153 |             $this->addMessage("Queueing the next Cleanup Job."); | ||
| 154 | $cleanup = new CleanupJob(); | ||
| 155 |             singleton('SilverStripe\\QueuedJobs\\Services\\QueuedJobService') | ||
| 156 |                 ->queueJob($cleanup, date('Y-m-d H:i:s', time() + 86400)); | ||
| 157 | } | ||
| 158 | $this->isComplete = true; | ||
| 159 | return; | ||
| 160 | } | ||
| 161 | } | ||
| 162 | 
This check marks private properties in classes that are never used. Those properties can be removed.