Conditions | 17 |
Paths | 72 |
Total Lines | 103 |
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 |
||
28 | public function getModifierForm(Controller $optionalController = NULL, Validator $optionalValidator = NULL) |
||
29 | { |
||
30 | $showCreateRepeatOrderForm = false; |
||
31 | $fields = FieldList::create(); |
||
32 | $actions = null; |
||
33 | $fields->push($this->headingField()); |
||
34 | $fields->push($this->descriptionField()); |
||
35 | $order = ShoppingCart::current_order(); |
||
36 | $currentMember = Member::currentUser(); |
||
37 | |||
38 | $repeatOrder = null; |
||
39 | if($order && $order->exists()) { |
||
40 | $orderID = $order->ID; |
||
41 | $repeatOrder = DataObject::get_one('RepeatOrder', ['OriginatingOrderID' => $order->ID]); |
||
42 | } else { |
||
43 | $orderID = 0; |
||
44 | } |
||
45 | $createLink = RepeatOrdersPage::get_repeat_order_link('createorder', $orderID); |
||
46 | $allowNonMembers = Config::inst()->get('RepeatOrder', 'allow_non_members'); |
||
47 | |||
48 | if (($repeatOrder && $currentMember) || ($repeatOrder && $allowNonMembers)) { |
||
49 | if ($repeatOrder->canModify()) { |
||
50 | $repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields($repeatOrder->ID, $orderID, true); |
||
51 | foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
||
52 | $fields->push( |
||
53 | $repeatOrderFormField |
||
54 | ); |
||
55 | } |
||
56 | |||
57 | $cancelRepeatOrderLink = RepeatOrdersPage::get_repeat_order_link('ajaxcheckoutcancel', $repeatOrder->ID); |
||
58 | $fields->push( |
||
59 | HiddenField::create('AjaxCancelLink', 'AjaxCancelLink', $cancelRepeatOrderLink) |
||
60 | ); |
||
61 | |||
62 | $actions = RepeatOrderForm::repeatOrderFormActions('Update', $repeatOrder); |
||
63 | $actions->push( |
||
64 | FormAction::create('doCancel', 'Cancel Subscription') |
||
65 | ); |
||
66 | } |
||
67 | else { |
||
68 | $showCreateRepeatOrderForm = true; |
||
69 | } |
||
70 | Requirements::customScript("jQuery(document).ready(function(){jQuery(\"input[name='action_processOrder']\").hide();});", "hide_action_processOrder"); |
||
71 | } elseif ($currentMember || $allowNonMembers) { |
||
72 | //this shouldn't actually happen as the repeat order should have been found and used in the previous if statement |
||
73 | if ($order->RepeatOrderID) { |
||
74 | $fields->push( |
||
75 | LiteralField::create( |
||
76 | "whatAreRepeatOrders", |
||
77 | '<div id="WhatAreRepeatOrders">This order is based on a Repeat Order.</div>' |
||
78 | ) |
||
79 | ); |
||
80 | } else { |
||
81 | $showCreateRepeatOrderForm = true; |
||
82 | } |
||
83 | } else { |
||
84 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
85 | if ($page) { |
||
86 | $fields->push( |
||
87 | LiteralField::create( |
||
88 | "whatAreRepeatOrders", |
||
89 | '<div id="WhatAreRepeatOrders">' . $page->OnceLoggedInYouCanCreateRepeatOrder . '</div>' |
||
90 | ) |
||
91 | ); |
||
92 | } |
||
93 | } |
||
94 | |||
95 | if($showCreateRepeatOrderForm){ |
||
96 | $repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields(0, $orderID); |
||
97 | foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
||
98 | $fields->push( |
||
99 | $repeatOrderFormField |
||
100 | ); |
||
101 | } |
||
102 | |||
103 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
104 | if ($page) { |
||
105 | $fields->push( |
||
106 | LiteralField::create("whatAreRepeatOrders", |
||
107 | '<div id="WhatAreRepeatOrders">' . $page->WhatAreRepeatOrders . '</div>' |
||
108 | ) |
||
109 | ); |
||
110 | } |
||
111 | |||
112 | $actions = RepeatOrderForm::repeatOrderFormActions('Confirm and Pay'); |
||
113 | |||
114 | //required fields |
||
115 | $requiredArray = array('Start', 'Period'); |
||
116 | $optionalValidator = RequiredFields::create($requiredArray); |
||
117 | } |
||
118 | |||
119 | if($actions === NULL){ |
||
120 | $actions = FieldList::create(); |
||
121 | } |
||
122 | |||
123 | return RepeatOrderModifierForm::create( |
||
124 | $optionalController, |
||
125 | 'RepeatOrderModifier', |
||
126 | $fields, |
||
127 | $actions, |
||
128 | $optionalValidator |
||
129 | ); |
||
130 | } |
||
131 | |||
186 |
Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a
@return
annotation as described here.