Conditions | 4 |
Paths | 5 |
Total Lines | 63 |
Code Lines | 43 |
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 |
||
81 | public function process() { |
||
82 | $statusList = implode('\', \'', $this->config()->cleanup_statuses); |
||
83 | switch($this->config()->cleanup_method) { |
||
84 | // If Age, we need to get jobs that are at least n days old |
||
85 | case "age": |
||
86 | $cutOff = date("Y-m-d H:i:s", |
||
87 | strtotime(SS_Datetime::now() . |
||
88 | " - " . |
||
89 | $this->config()->cleanup_value . |
||
90 | " days" |
||
91 | ) |
||
92 | ); |
||
93 | $stale = DB::query( |
||
94 | 'SELECT "ID" |
||
95 | FROM "QueuedJobDescriptor" |
||
96 | WHERE "JobStatus" |
||
97 | IN (\'' . $statusList . '\') |
||
98 | AND "LastEdited" < \'' . $cutOff .'\'' |
||
99 | ); |
||
100 | $staleJobs = $stale->column("ID"); |
||
101 | break; |
||
102 | // If Number, we need to save n records, then delete from the rest |
||
103 | case "number": |
||
104 | $fresh = DB::query( |
||
105 | 'SELECT "ID" |
||
106 | FROM "QueuedJobDescriptor" |
||
107 | ORDER BY "LastEdited" |
||
108 | ASC LIMIT ' . $this->config()->cleanup_value |
||
109 | ); |
||
110 | $freshJobIDs = implode('\', \'', $fresh->column("ID")); |
||
111 | |||
112 | $stale = DB::query( |
||
113 | 'SELECT "ID" |
||
114 | FROM "QueuedJobDescriptor" |
||
115 | WHERE "ID" |
||
116 | NOT IN (\'' . $freshJobIDs . '\') |
||
117 | AND "JobStatus" |
||
118 | IN (\'' . $statusList . '\')' |
||
119 | ); |
||
120 | $staleJobs = $stale->column("ID"); |
||
121 | break; |
||
122 | default: |
||
123 | $this->addMessage("Incorrect configuration values set. Cleanup ignored"); |
||
124 | $this->isComplete = true; |
||
125 | return; |
||
126 | } |
||
127 | if (empty($staleJobs)) { |
||
128 | $this->addMessage("No jobs to clean up."); |
||
129 | $this->isComplete = true; |
||
130 | $this->reenqueue(); |
||
131 | return; |
||
132 | } |
||
133 | $numJobs = count($staleJobs); |
||
134 | $staleJobs = implode('\', \'', $staleJobs); |
||
135 | DB::query('DELETE FROM "QueuedJobDescriptor" |
||
136 | WHERE "ID" |
||
137 | IN (\'' . $staleJobs . '\')' |
||
138 | ); |
||
139 | $this->addMessage($numJobs . " jobs cleaned up."); |
||
140 | $this->reenqueue(); |
||
141 | $this->isComplete = true; |
||
142 | return; |
||
143 | } |
||
144 | |||
155 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.