| Conditions | 16 |
| Paths | 32 |
| Total Lines | 77 |
| Code Lines | 68 |
| Lines | 40 |
| Ratio | 51.95 % |
| 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 |
||
| 73 | public function processform() |
||
| 74 | { |
||
| 75 | $bt = defined('DB::USE_ANSI_SQL') ? "\"" : "`"; |
||
| 76 | $where = array(); |
||
| 77 | $having = array(); |
||
| 78 | $humanWhere = array(); |
||
| 79 | foreach ($_REQUEST as $key => $value) { |
||
| 80 | $value = Convert::raw2sql($value); |
||
| 81 | if ($value) { |
||
| 82 | switch ($key) { |
||
| 83 | case "OrderID": |
||
| 84 | $where[] = " {$bt}Order{$bt}.{$bt}ID{$bt} = ".intval($value); |
||
| 85 | $humanWhere[] = ' OrderID equals '.intval($value); |
||
| 86 | break; |
||
| 87 | View Code Duplication | case "From": |
|
| 88 | $d = new Date("date"); |
||
| 89 | $d->setValue($value); |
||
| 90 | $t = new Time("time"); |
||
| 91 | $cleanTime = trim(preg_replace('/([ap]m)/', "", Convert::raw2sql($_REQUEST["FromTime"]))); |
||
| 92 | $t->setValue($cleanTime); // |
||
| 93 | $exactTime = strtotime($d->format("Y-m-d")." ".$t->Nice24()); |
||
| 94 | $where[] = " UNIX_TIMESTAMP({$bt}Order{$bt}.{$bt}Created{$bt}) >= '".$exactTime."'"; |
||
| 95 | $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) |
||
| 96 | break; |
||
| 97 | View Code Duplication | case "Until": |
|
| 98 | $d = new Date("date"); |
||
| 99 | $d->setValue($value); |
||
| 100 | $t = new Time("time"); |
||
| 101 | $cleanTime = trim(preg_replace('/([ap]m)/', "", Convert::raw2sql($_REQUEST["FromTime"]))); |
||
| 102 | $t->setValue($cleanTime); // |
||
| 103 | $exactTime = strtotime($d->format("Y-m-d")." ".$t->Nice24()); |
||
| 104 | $where[] = " UNIX_TIMESTAMP({$bt}Order{$bt}.{$bt}Created{$bt}) <= '".$exactTime."'"; |
||
| 105 | $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) |
||
| 106 | break; |
||
| 107 | View Code Duplication | case "Email": |
|
| 108 | $where[] = " {$bt}Member{$bt}.{$bt}Email{$bt} = '".$value."'"; |
||
| 109 | $humanWhere[] = ' Customer Email equals "'.$value.'"'; |
||
| 110 | break; |
||
| 111 | View Code Duplication | case "FirstName": |
|
| 112 | $where[] = " {$bt}Member{$bt}.{$bt}FirstName{$bt} LIKE '%".$value."%'"; |
||
| 113 | $humanWhere[] = ' Customer First Name equals '.$value.'"'; |
||
| 114 | break; |
||
| 115 | View Code Duplication | case "Surname": |
|
| 116 | $where[] = " {$bt}Member{$bt}.{$bt}Surname{$bt} LIKE '%".$value."%'"; |
||
| 117 | $humanWhere[] = ' Customer Surname equals "'.$value.'"'; |
||
| 118 | break; |
||
| 119 | case "Status": |
||
| 120 | $subWhere = array(); |
||
| 121 | foreach ($value as $item) { |
||
| 122 | $subWhere[] = " {$bt}Order{$bt}.{$bt}Status{$bt} = '".$item."'"; |
||
| 123 | $humanWhere[] = ' Order Status equals "'.$item.'"'; |
||
| 124 | } |
||
| 125 | if (count($subWhere)) { |
||
| 126 | $where[] = implode(" OR ", $subWhere); |
||
| 127 | } |
||
| 128 | break; |
||
| 129 | View Code Duplication | case "HasMinimumPayment": |
|
| 130 | $having[] = ' RealPayments > '.intval($value); |
||
| 131 | $humanWhere[] = ' Real Payment of at least '.$this->currencyFormat($value); |
||
| 132 | break; |
||
| 133 | View Code Duplication | case "HasMaximumPayment": |
|
| 134 | $having[] = ' RealPayments < '.intval($value); |
||
| 135 | $humanWhere[] = ' Real Payment of no more than '.$this->currencyFormat($value); |
||
| 136 | break; |
||
| 137 | //this has been included for SearchableProductSalesReport |
||
| 138 | case "Product": |
||
| 139 | $where[] = " IF(ProductVariationsForVariations.Title IS NOT NULL, CONCAT(ProductSiteTreeForVariations.Title,' : ', ProductVariationsForVariations.Title), IF(SiteTreeForProducts.Title IS NOT NULL, SiteTreeForProducts.Title, OrderAttribute.ClassName)) LIKE '%".$value."%'"; |
||
| 140 | $humanWhere[] = ' Product includes the phrase '.$value.'"'; |
||
| 141 | break; |
||
| 142 | |||
| 143 | default: |
||
| 144 | break; |
||
| 145 | } |
||
| 146 | } |
||
| 147 | } |
||
| 148 | return $this->saveProcessedForm($having, $where, $humanWhere); |
||
| 149 | } |
||
| 150 | |||
| 259 |
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.