Conditions | 13 |
Paths | 720 |
Total Lines | 70 |
Code Lines | 49 |
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 | $queueObjectSingleton = Injector::inst()->get('OrderProcessQueue'); |
||
56 | $ordersinQueue = $queueObjectSingleton->OrdersToBeProcessed(0); |
||
57 | //find any other order that may need help ... |
||
58 | |||
59 | $submittedOrderStatusLogClassName = EcommerceConfig::get('OrderStatusLog', 'order_status_log_class_used_for_submitting_order'); |
||
60 | if ($submittedOrderStatusLogClassName) { |
||
61 | $submittedStatusLog = $submittedOrderStatusLogClassName::get()->First(); |
||
62 | if ($submittedStatusLog) { |
||
63 | $lastOrderStep = OrderStep::get()->Last(); |
||
64 | if ($lastOrderStep) { |
||
65 | if($this->isCli()) { |
||
66 | $sort = 'RAND()'; |
||
67 | } else { |
||
68 | $sort = array('ID' => 'ASC'); |
||
69 | } |
||
70 | $orders = Order::get() |
||
71 | ->sort($sort) |
||
72 | ->where('StatusID <> ' . $lastOrderStep->ID) |
||
73 | ->exclude(array('ID' => $ordersinQueue->column('ID'))) |
||
74 | ->innerJoin( |
||
75 | 'OrderStatusLog', |
||
76 | "\"OrderStatusLog\".\"OrderID\" = \"Order\".\"ID\"" |
||
77 | ) |
||
78 | ->innerJoin( |
||
79 | $submittedOrderStatusLogClassName, |
||
80 | "\"$submittedOrderStatusLogClassName\".\"ID\" = \"OrderStatusLog\".\"ID\"" |
||
81 | ); |
||
82 | $startAt = $this->tryToFinaliseOrders($orders, $limit, $startAt); |
||
83 | } else { |
||
84 | DB::alteration_message('NO order step.', 'deleted'); |
||
85 | } |
||
86 | } else { |
||
87 | DB::alteration_message('NO submitted order status log.', 'deleted'); |
||
88 | } |
||
89 | } else { |
||
90 | DB::alteration_message('NO EcommerceConfig::get("OrderStatusLog", "order_status_log_class_used_for_submitting_order")', 'deleted'); |
||
91 | } |
||
92 | if (Session::get('EcommerceTaskTryToFinaliseOrders')) { |
||
93 | if(! $this->isCli()) { |
||
94 | DB::alteration_message('WAIT: we are still moving more orders ... this page will automatically load the next lot in 5 seconds.', 'deleted'); |
||
95 | echo '<script type="text/javascript">window.setTimeout(function() {location.reload();}, 5000);</script>'; |
||
96 | } |
||
97 | } |
||
98 | } |
||
99 | |||
146 |
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.