Conditions | 7 |
Paths | 36 |
Total Lines | 80 |
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 |
||
24 | public function __construct($name, $title = "") |
||
25 | { |
||
26 | $totalNumberOfDaysBack = $this->numberOfDays + $this->endingDaysBack; |
||
27 | $data = DB::query(" |
||
28 | SELECT COUNT(ID) myCount, \"Title\" |
||
29 | FROM \"GoogleCustomSearchPage_Record\" |
||
30 | WHERE Created > ( NOW() - INTERVAL ".$totalNumberOfDaysBack." DAY ) |
||
31 | AND Created < ( NOW() - INTERVAL ".$this->endingDaysBack." DAY ) |
||
32 | GROUP BY \"Title\" |
||
33 | HAVING COUNT(\"ID\") >= $this->minimumCount |
||
34 | ORDER BY myCount DESC |
||
35 | "); |
||
36 | if (!$this->minimumCount) { |
||
37 | $this->minimumCount++; |
||
38 | } |
||
39 | $content = ""; |
||
40 | if ($title) { |
||
41 | $content .= "<h2>".$title."</h2>"; |
||
42 | } |
||
43 | $content .= " |
||
44 | <div id=\"SearchHistoryTableForCMS\"> |
||
45 | <h3>Search Phrases entered at least ".$this->minimumCount." times between ".date("Y-M-d", strtotime("-".$totalNumberOfDaysBack." days"))." and ".date("Y-M-d", strtotime("-".$this->endingDaysBack." days"))."</h3> |
||
46 | <table class=\"highToLow\" style=\"width: 100%;\">"; |
||
47 | $list = array(); |
||
48 | foreach ($data as $key => $row) { |
||
49 | if (!$key) { |
||
50 | $maxWidth = $row["myCount"]; |
||
51 | } |
||
52 | $multipliedWidthInPercentage = floor(($row["myCount"] / $maxWidth)* 100); |
||
53 | $list[$row["myCount"]."-".$key] = $row["Title"]; |
||
54 | $content .=' |
||
55 | <tr> |
||
56 | <td style="text-align: right; width: 30%; padding: 5px;"> |
||
57 | '.$row["Title"].' |
||
58 | </td> |
||
59 | <td style="background-color: silver; padding: 5px; width: 70%;"> |
||
60 | <div style="width: '.$multipliedWidthInPercentage.'%; background-color: #0066CC; color: #fff;">'.$row["myCount"].'</div> |
||
61 | </td> |
||
62 | </tr>'; |
||
63 | } |
||
64 | $content .= ' |
||
65 | </table>'; |
||
66 | //a - z |
||
67 | asort($list); |
||
68 | $content .= " |
||
69 | <h3>A - Z with favourite links clicked</h3> |
||
70 | <table class=\"aToz\" style=\"width: 100%;\">"; |
||
71 | foreach ($list as $key => $title) { |
||
72 | $array = explode("-", $key); |
||
73 | $multipliedWidthInPercentage = floor(($array[0] / $maxWidth)* 100); |
||
74 | $titleData = DB::query(" |
||
75 | SELECT COUNT(ID) myCount, \"URL\" |
||
76 | FROM \"GoogleCustomSearchPage_Record\" |
||
77 | WHERE Created > ( NOW() - INTERVAL ".$totalNumberOfDaysBack." DAY ) |
||
78 | AND Created < ( NOW() - INTERVAL ".$this->endingDaysBack." DAY ) |
||
79 | AND \"Title\" = '".$title."' |
||
80 | GROUP BY \"URL\" |
||
81 | HAVING COUNT(\"ID\") >= $this->minimumCount |
||
82 | ORDER BY myCount DESC |
||
83 | LIMIT 3; |
||
84 | "); |
||
85 | unset($urlArray); |
||
86 | $urlArray = array(); |
||
87 | foreach ($titleData as $urlRow) { |
||
88 | $urlArray[] = "<li>".$urlRow["myCount"].": ".$urlRow["URL"]."</li>"; |
||
89 | } |
||
90 | $content .=' |
||
91 | <tr> |
||
92 | <td style="text-align: right; width: 30%; padding: 5px;">'.$title.'</td> |
||
93 | <td style="background-color: silver; padding: 5px; width: 70%"> |
||
94 | <div style="width: '.$multipliedWidthInPercentage.'%; background-color: #0066CC; color: #fff;">'.trim($array[0]).'</div> |
||
95 | <ul style="font-size: 10px">'.implode($urlArray).'</ul> |
||
96 | </td> |
||
97 | </tr>'; |
||
98 | } |
||
99 | $content .= ' |
||
100 | </table> |
||
101 | </div>'; |
||
102 | return parent::__construct($name, $content); |
||
103 | } |
||
104 | |||
135 |
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.