Conditions | 12 |
Paths | 24 |
Total Lines | 63 |
Code Lines | 55 |
Lines | 29 |
Ratio | 46.03 % |
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 |
||
74 | public function processform() |
||
75 | { |
||
76 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
77 | $where = array(); |
||
78 | $having = array(); |
||
79 | $humanWhere = array(); |
||
80 | foreach ($_REQUEST as $key => $value) { |
||
81 | $value = Convert::raw2sql($value); |
||
82 | if ($value) { |
||
83 | switch ($key) { |
||
84 | case "OrderID": |
||
85 | $where[] = ' {$bt}Order{$bt}.{$bt}ID{$bt} = '.intval($value); |
||
86 | $humanWhere[] = ' OrderID equals '.intval($value); |
||
87 | break; |
||
88 | View Code Duplication | case "From": |
|
89 | $d = new Date("date"); |
||
90 | $d->setValue($value); |
||
91 | $t = new Time("time"); |
||
92 | $cleanTime = trim(preg_replace('/([ap]m)/', "", Convert::raw2sql($_REQUEST["FromTime"]))); |
||
93 | $t->setValue($cleanTime); // |
||
94 | $exactTime = strtotime($d->format("Y-m-d")." ".$t->Nice24()); |
||
95 | $where[] = ' UNIX_TIMESTAMP({$bt}Payment{$bt}.{$bt}Created{$bt}) >= "'.$exactTime.'"'; |
||
96 | $humanWhere[] = ' Order on or after '.Date("r", $exactTime);//r = Example: Thu, 21 Dec 2000 16:01:07 +0200 // also consider: l jS \of F Y H:i Z(e) |
||
97 | break; |
||
98 | View Code Duplication | case "Until": |
|
99 | $d = new Date("date"); |
||
100 | $d->setValue($value); |
||
101 | $t = new Time("time"); |
||
102 | $cleanTime = trim(preg_replace('/([ap]m)/', "", Convert::raw2sql($_REQUEST["FromTime"]))); |
||
103 | $t->setValue($cleanTime); // |
||
104 | $exactTime = strtotime($d->format("Y-m-d")." ".$t->Nice24()); |
||
105 | $where[] = ' UNIX_TIMESTAMP({$bt}Payment{$bt}.{$bt}Created{$bt}) <= "'.$exactTime.'"'; |
||
106 | $humanWhere[] = ' Order before or on '.Date("r", $exactTime);//r = Example: Thu, 21 Dec 2000 16:01:07 +0200 // also consider: l jS \of F Y H:i Z(e) |
||
107 | |||
108 | break; |
||
109 | case "Status": |
||
110 | $subWhere = array(); |
||
111 | foreach ($value as $item) { |
||
112 | $subWhere[] = ' {$bt}Payment{$bt}.{$bt}Status{$bt} = "'.$item.'"'; |
||
113 | $humanWhere[] = ' Payment Status equals "'.$item.'"'; |
||
114 | } |
||
115 | if (count($subWhere)) { |
||
116 | $where[] = implode(" OR ", $subWhere); |
||
117 | } |
||
118 | break; |
||
119 | View Code Duplication | case "HasMinimumPayment": |
|
120 | $having[] = ' Amount > '.intval($value); |
||
121 | $humanWhere[] = ' Payment of at least '.$this->currencyFormat($value); |
||
122 | break; |
||
123 | View Code Duplication | case "HasMaximumPayment": |
|
124 | $having[] = ' Amount < '.intval($value); |
||
125 | $humanWhere[] = ' Payment of no more than '.$this->currencyFormat($value); |
||
126 | break; |
||
127 | default: |
||
128 | break; |
||
129 | } |
||
130 | } |
||
131 | } |
||
132 | Session::set("SearchablePaymentReport.having", implode(" AND ", $having)); |
||
133 | Session::set("SearchablePaymentReport.where", implode(" AND", $where)); |
||
134 | Session::set("SearchablePaymentReport.humanWhere", implode(", ", $humanWhere)); |
||
135 | return "ok"; |
||
136 | } |
||
137 | |||
213 |
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.