Conditions | 15 |
Paths | 192 |
Total Lines | 90 |
Code Lines | 50 |
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 |
||
147 | public function Field($properties = array()) |
||
148 | { |
||
149 | $title = $this->getContent(); |
||
150 | $totalNumberOfDaysBack = $this->numberOfDays + $this->endingDaysBack; |
||
151 | $data = DB::query(' |
||
152 | SELECT COUNT(ID) myCount, "Title" |
||
153 | FROM "SearchHistory" |
||
154 | WHERE Created > ( NOW() - INTERVAL '.$totalNumberOfDaysBack.' DAY ) |
||
155 | AND Created < ( NOW() - INTERVAL '.$this->endingDaysBack." DAY ) |
||
156 | GROUP BY \"Title\" |
||
157 | HAVING COUNT(\"ID\") >= $this->minimumCount |
||
158 | ORDER BY myCount DESC |
||
159 | LIMIT ".$this->maxRows." |
||
160 | "); |
||
161 | if (!$this->minimumCount) { |
||
162 | ++$this->minimumCount; |
||
163 | } |
||
164 | $content = ''; |
||
165 | $tableContent = ''; |
||
166 | if ($title && $this->addTitle) { |
||
167 | $content .= '<h3>'.$title.'</h3>'; |
||
168 | } |
||
169 | $content .= ' |
||
170 | <div id="SearchHistoryTableForCMS"> |
||
171 | <h3> |
||
172 | Search Phrases' |
||
173 | .($this->minimumCount > 1 ? ', entered at least '.$this->minimumCount.' times' : '') |
||
174 | .($this->maxRows < 1000 ? ', limited to '.$this->maxRows.' entries, ' : '') |
||
175 | .' between '.date('j-M-Y', strtotime('-'.$totalNumberOfDaysBack.' days')).' and '.date('j-M-Y', strtotime('-'.$this->endingDaysBack.' days')).' |
||
176 | </h3>'; |
||
177 | $count = 0; |
||
178 | if ($data && count($data)) { |
||
179 | $tableContent .= ' |
||
180 | <table class="highToLow" style="widht: 100%">'; |
||
181 | $list = array(); |
||
182 | foreach ($data as $key => $row) { |
||
183 | $count++; |
||
184 | //for the highest count, we work out a max-width |
||
185 | if (!$key) { |
||
186 | $maxWidth = $row['myCount']; |
||
187 | } |
||
188 | $multipliedWidthInPercentage = floor(($row['myCount'] / $maxWidth) * 100); |
||
189 | $list[$row['myCount'].'-'.$key] = $row['Title']; |
||
190 | $tableContent .= ' |
||
191 | <tr> |
||
192 | <td style="text-align: right; width: 30%; padding: 5px;">'.$row['Title'].'</td> |
||
193 | <td style="background-color: silver; padding: 5px; width: 70%;"> |
||
194 | <div style="width: '.$multipliedWidthInPercentage.'%; background-color: #C51162; color: #fff;">'.$row['myCount'].'</div> |
||
195 | </td> |
||
196 | </tr>'; |
||
197 | } |
||
198 | $tableContent .= ' |
||
199 | </table>'; |
||
200 | if ($count && $this->addAtoZ) { |
||
201 | asort($list); |
||
202 | $tableContent .= ' |
||
203 | <h3>A - Z</h3> |
||
204 | <table class="aToz" style="widht: 100%">'; |
||
205 | foreach ($list as $key => $title) { |
||
206 | $array = explode('-', $key); |
||
207 | $multipliedWidthInPercentage = floor(($array[0] / $maxWidth) * 100); |
||
208 | $tableContent .= ' |
||
209 | <tr> |
||
210 | <td style="text-align: right; width: 30%; padding: 5px;">'.$title.'</td> |
||
211 | <td style="background-color: silver; padding: 5px; width: 70%"> |
||
212 | <div style="width: '.$multipliedWidthInPercentage.'%; background-color: #004D40; color: #fff;">'.trim($array[0]).'</div> |
||
213 | </td> |
||
214 | </tr>'; |
||
215 | } |
||
216 | $tableContent .= ' |
||
217 | </table>'; |
||
218 | } |
||
219 | } |
||
220 | if ($count === 0) { |
||
221 | //we replace table content here... |
||
222 | $tableContent = '<p class="warning message">No searches found.</p>'; |
||
223 | } |
||
224 | $content .= $tableContent; |
||
225 | if ($this->showMoreLink) { |
||
226 | $content .= ' |
||
227 | <p> |
||
228 | <a href="/dev/tasks/EcommerceTaskReviewSearches/">Query more resuts</a> |
||
229 | </p>'; |
||
230 | } else { |
||
231 | } |
||
232 | $content .= ' |
||
233 | </div>'; |
||
234 | |||
235 | return $content; |
||
236 | } |
||
237 | } |
||
238 |
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.