Conditions | 11 |
Paths | 384 |
Total Lines | 60 |
Code Lines | 41 |
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 |
||
29 | public function run($request) |
||
30 | { |
||
31 | //IMPORTANT! |
||
32 | if ( ! $this->sendEmails) { |
||
33 | Config::inst()->update('Email', 'send_all_emails_to', 'no-one@localhost'); |
||
34 | Email::set_mailer(new Ecommerce_Dummy_Mailer()); |
||
35 | } |
||
36 | |||
37 | //get limits |
||
38 | $limit = null; |
||
39 | if (isset($_GET['limit'])) { |
||
40 | $limit = intval($_GET['limit']); |
||
41 | } |
||
42 | if (!intval($limit)) { |
||
43 | $limit = $this->limit; |
||
44 | } |
||
45 | $startAt = null; |
||
46 | if (isset($_GET['startat'])) { |
||
47 | $startAt = intval($_GET['startat']); |
||
48 | } |
||
49 | if (!intval($startAt)) { |
||
50 | $startAt = intval(Session::get('EcommerceTaskTryToFinaliseOrders')); |
||
51 | if (!$startAt) { |
||
52 | $startAt = 0; |
||
53 | } |
||
54 | } |
||
55 | |||
56 | |||
57 | $this->tryToFinaliseOrders($ordersinQueue, $limit, $startAt); |
||
58 | |||
59 | //find any other order that may need help ... |
||
60 | $orderStatusLogClassName = 'OrderStatusLog'; |
||
61 | $submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
||
62 | if ($submittedOrderStatusLogClassName) { |
||
63 | $submittedStatusLog = $submittedOrderStatusLogClassName::get()->First(); |
||
64 | if ($submittedStatusLog) { |
||
65 | $startAtOrderStep = OrderStep::get()->sort('Sort', 'DESC')->First(); |
||
66 | if ($startAtOrderStep) { |
||
67 | $joinSQL = 'INNER JOIN "" ON '; |
||
68 | $whereSQL = '"StatusID" <> '.$startAtOrderStep->ID.''; |
||
69 | $orders = Order::get() |
||
70 | ->where($whereSQL) |
||
71 | ->sort('ID', 'ASC') |
||
72 | ->exclude(array('ID' => $ordersinQueue->column('ID'))) |
||
73 | ->innerJoin($orderStatusLogClassName, "\"$orderStatusLogClassName\".\"OrderID\" = \"Order\".\"ID\""); |
||
74 | $startAt = $this->tryToFinaliseOrders($orders, $limit, $startAt); |
||
75 | } else { |
||
76 | DB::alteration_message('NO order step.', 'deleted'); |
||
77 | } |
||
78 | } else { |
||
79 | DB::alteration_message('NO submitted order status log.', 'deleted'); |
||
80 | } |
||
81 | } else { |
||
82 | DB::alteration_message('NO EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order")', 'deleted'); |
||
83 | } |
||
84 | if (Session::get('EcommerceTaskTryToFinaliseOrders')) { |
||
85 | DB::alteration_message('WAIT: we are still moving more orders ... this page will automatically load the next lot in 5 seconds.', 'deleted'); |
||
86 | echo '<script type="text/javascript">window.setTimeout(function() {location.reload();}, 5000);</script>'; |
||
87 | } |
||
88 | } |
||
89 | |||
134 |
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.