| Conditions | 8 |
| Paths | 9 |
| Total Lines | 95 |
| Code Lines | 68 |
| 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 |
||
| 51 | public function preparePage() |
||
| 52 | { |
||
| 53 | $this->P = new \HaaseIT\HCSF\CorePage($this->serviceManager); |
||
| 54 | $this->P->cb_pagetype = 'content'; |
||
| 55 | |||
| 56 | if (!CHelper::getUserData()) { |
||
| 57 | $this->P->oPayload->cl_html = $this->textcats->T("denied_notloggedin"); |
||
| 58 | } else { |
||
| 59 | require_once PATH_BASEDIR . 'src/shop/functions.shoppingcart.php'; |
||
| 60 | |||
| 61 | $this->P->cb_customcontenttemplate = 'shop/myorders'; |
||
| 62 | |||
| 63 | if (isset($_GET["action"], $_GET["id"]) && $_GET["action"] === 'show') { |
||
| 64 | $iId = \filter_input(INPUT_GET, 'id', FILTER_SANITIZE_NUMBER_INT); |
||
| 65 | |||
| 66 | $sql = "SELECT * FROM " . 'orders WHERE o_id = :id AND o_custno = \'' . $_SESSION['user']['cust_no'] . '\' AND o_ordercompleted != \'d\''; |
||
| 67 | $hResult = $this->db->prepare($sql); |
||
| 68 | $hResult->bindValue(':id', $iId); |
||
| 69 | $hResult->execute(); |
||
| 70 | |||
| 71 | if ($hResult->rowCount() == 1) { |
||
| 72 | $aOrder = $hResult->fetch(); |
||
| 73 | |||
| 74 | $this->P->cb_customdata['orderdata']['ordertimestamp'] = date( |
||
| 75 | HelperConfig::$core["locale_format_date_time"], |
||
| 76 | $aOrder["o_ordertimestamp"] |
||
| 77 | ); |
||
| 78 | $this->P->cb_customdata['orderdata']['orderremarks'] = $aOrder["o_remarks"]; |
||
| 79 | $this->P->cb_customdata['orderdata']['paymentmethod'] = $this->textcats->T("order_paymentmethod_" . $aOrder["o_paymentmethod"]); |
||
| 80 | $this->P->cb_customdata['orderdata']['paymentcompleted'] = (($aOrder["o_paymentcompleted"] == 'y') ? $this->textcats->T("myorders_paymentstatus_completed") : $this->textcats->T("myorders_paymentstatus_open")); |
||
| 81 | $this->P->cb_customdata['orderdata']['orderstatus'] = SHelper::showOrderStatusText($this->textcats, $aOrder["o_ordercompleted"]); |
||
| 82 | $this->P->cb_customdata['orderdata']['shippingservice'] = $aOrder["o_shipping_service"]; |
||
| 83 | $this->P->cb_customdata['orderdata']['trackingno'] = $aOrder["o_shipping_trackingno"]; |
||
| 84 | |||
| 85 | $sql = 'SELECT * FROM orders_items WHERE oi_o_id = :id'; |
||
| 86 | $hResult = $this->db->prepare($sql); |
||
| 87 | $hResult->bindValue(':id', $iId); |
||
| 88 | $hResult->execute(); |
||
| 89 | |||
| 90 | $aItems = $hResult->fetchAll(); |
||
| 91 | |||
| 92 | $aItemsforShoppingcarttable = []; |
||
| 93 | foreach ($aItems as $aValue) { |
||
| 94 | $aPrice = [ |
||
| 95 | 'netto_use' => $aValue["oi_price_netto_use"], |
||
| 96 | 'brutto_use' => $aValue["oi_price_brutto_use"], |
||
| 97 | ]; |
||
| 98 | $aItemsforShoppingcarttable[$aValue["oi_cartkey"]] = [ |
||
| 99 | 'amount' => $aValue["oi_amount"], |
||
| 100 | 'price' => $aPrice, |
||
| 101 | 'vat' => $aValue["oi_vat"], |
||
| 102 | //'rg' => $aValue["oi_rg"], |
||
| 103 | 'name' => $aValue["oi_itemname"], |
||
| 104 | 'img' => $aValue["oi_img"], |
||
| 105 | ]; |
||
| 106 | } |
||
| 107 | |||
| 108 | $aShoppingcart = SHelper::buildShoppingCartTable( |
||
| 109 | $aItemsforShoppingcarttable, |
||
| 110 | true, |
||
| 111 | '', |
||
| 112 | '', |
||
| 113 | $aOrder["o_vatfull"], |
||
| 114 | $aOrder["o_vatreduced"] |
||
| 115 | ); |
||
| 116 | } else { |
||
| 117 | $this->P->cb_customdata['ordernotfound'] = true; |
||
| 118 | } |
||
| 119 | } else { |
||
| 120 | $COList = [ |
||
| 121 | ['title' => $this->textcats->T("order_head_orderdate"), 'key' => 'o_ordertime', 'width' => 110, 'linked' => false,], |
||
| 122 | ['title' => $this->textcats->T("order_head_paymenthethod"), 'key' => 'o_paymentmethod', 'width' => 125, 'linked' => false,], |
||
| 123 | ['title' => $this->textcats->T("order_head_paid"), 'key' => 'o_paymentcompleted', 'width' => 60, 'linked' => false,], |
||
| 124 | ['title' => $this->textcats->T("order_head_status"), 'key' => 'o_order_status', 'width' => 80, 'linked' => false,], |
||
| 125 | ['title' => $this->textcats->T("order_head_shipping_service"), 'key' => 'o_shipping_service', 'width' => 90, 'linked' => false,], |
||
| 126 | ['title' => $this->textcats->T("order_head_shipping_trackingno"), 'key' => 'o_shipping_trackingno', 'width' => 130, 'linked' => false,], |
||
| 127 | [ |
||
| 128 | 'title' => $this->textcats->T("order_show"), |
||
| 129 | 'key' => 'o_id', |
||
| 130 | 'width' => 120, |
||
| 131 | 'linked' => true, |
||
| 132 | 'ltarget' => '/_misc/myorders.html', |
||
| 133 | 'lkeyname' => 'id', |
||
| 134 | 'lgetvars' => ['action' => 'show',], |
||
| 135 | ], |
||
| 136 | ]; |
||
| 137 | |||
| 138 | $this->P->cb_customdata['listmyorders'] = $this->showMyOrders($COList); |
||
| 139 | } |
||
| 140 | |||
| 141 | if (isset($aShoppingcart)) { |
||
| 142 | $this->P->cb_customdata['shoppingcart'] = $aShoppingcart['shoppingcart']; |
||
| 143 | } |
||
| 144 | } |
||
| 145 | } |
||
| 146 | |||
| 202 | } |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: