Conditions | 15 |
Paths | 28 |
Total Lines | 110 |
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 |
||
26 | public function getModifierForm(Controller $optionalController = NULL, Validator $optionalValidator = NULL) |
||
27 | { |
||
28 | $fields = FieldList::create(); |
||
29 | $actions = null; |
||
30 | $fields->push($this->headingField()); |
||
31 | $fields->push($this->descriptionField()); |
||
32 | $order = ShoppingCart::current_order(); |
||
33 | $currentMember = Member::currentUser(); |
||
34 | |||
35 | $repeatOrder = null; |
||
36 | if($order && $order->exists()) { |
||
37 | $orderID = $order->ID; |
||
38 | $repeatOrder = DataObject::get_one('RepeatOrder', ['OriginatingOrderID' => $order->ID]); |
||
39 | } else { |
||
40 | $orderID = 0; |
||
41 | } |
||
42 | $createLink = RepeatOrdersPage::get_repeat_order_link('createorder', $orderID); |
||
43 | $allowNonMembers = Config::inst()->get('RepeatOrder', 'allow_non_members'); |
||
44 | |||
45 | if (($repeatOrder && $currentMember) || ($repeatOrder && $allowNonMembers)) { |
||
46 | |||
47 | $updateLink = RepeatOrdersPage::get_repeat_order_link('modify', $repeatOrder->ID); |
||
48 | $cancelLink = RepeatOrdersPage::get_repeat_order_link('cancel', $repeatOrder->ID); |
||
49 | |||
50 | if ($repeatOrder->canModify()) { |
||
51 | $fields->push( |
||
52 | LiteralField::create( |
||
53 | 'modifyRepeatOrder', |
||
54 | <<<HTML |
||
55 | <div class="Actions"> |
||
56 | <input id="ModifyRepeatOrderUpdate" class="action" type="button" value="Edit your associated Repeat Order" onclick="window.location='{$updateLink}';" /> |
||
57 | </div> |
||
58 | HTML |
||
59 | ) |
||
60 | ); |
||
61 | } else { |
||
62 | $fields->push( |
||
63 | LiteralField::create( |
||
64 | 'createRepeatOrder', |
||
65 | <<<HTML |
||
66 | <div class="Actions"> |
||
67 | <input id="ModifyRepeatOrderCreate" class="action" type="button" value="Create a new Repeat Order" onclick="window.location='{$createLink}';" /> |
||
68 | </div> |
||
69 | HTML |
||
70 | ) |
||
71 | ); |
||
72 | } |
||
73 | Requirements::customScript("jQuery(document).ready(function(){jQuery(\"input[name='action_processOrder']\").hide();});", "hide_action_processOrder"); |
||
74 | } elseif ($currentMember || $allowNonMembers) { |
||
75 | if ($order->RepeatOrderID) { |
||
76 | $fields->push( |
||
77 | LiteralField::create( |
||
78 | "whatAreRepeatOrders", |
||
79 | <<<HTML |
||
80 | <div id="WhatAreRepeatOrders">This order is based on a Repeat Order.</div> |
||
81 | HTML |
||
82 | )); |
||
83 | } else { |
||
84 | $repeatOrderFormFields = RepeatOrderForm::repeatOrderFormFields(0, $orderID); |
||
85 | foreach ($repeatOrderFormFields as $repeatOrderFormField) { |
||
86 | $fields->push( |
||
87 | $repeatOrderFormField |
||
88 | ); |
||
89 | } |
||
90 | |||
91 | $repeatOrderFormLink = RepeatOrdersPage::get_repeat_order_link('ajaxcreateorder', $orderID); |
||
92 | $fields->push( |
||
93 | HiddenField::create('AjaxSubmissionLink', 'AjaxSubmissionLink', $repeatOrderFormLink) |
||
94 | ); |
||
95 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
96 | if ($page) { |
||
97 | $fields->push( |
||
98 | LiteralField::create("whatAreRepeatOrders", |
||
99 | <<<HTML |
||
100 | <div id="WhatAreRepeatOrders">$page->WhatAreRepeatOrders</div> |
||
101 | HTML |
||
102 | )); |
||
103 | } |
||
104 | |||
105 | $actions = RepeatOrderForm::repeatOrderFormActions('Confirm and Pay'); |
||
106 | |||
107 | //required fields |
||
108 | $requiredArray = array('Start', 'Period'); |
||
109 | $optionalValidator = RequiredFields::create($requiredArray); |
||
110 | } |
||
111 | } else { |
||
112 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
113 | if ($page) { |
||
114 | $fields->push( |
||
115 | LiteralField::create( |
||
116 | "whatAreRepeatOrders", |
||
117 | <<<HTML |
||
118 | <div id="WhatAreRepeatOrders">$page->OnceLoggedInYouCanCreateRepeatOrder</div> |
||
119 | HTML |
||
120 | )); |
||
121 | } |
||
122 | } |
||
123 | |||
124 | if($actions === NULL){ |
||
125 | $actions = FieldList::create(); |
||
126 | } |
||
127 | |||
128 | return RepeatOrderModifierForm::create( |
||
129 | $optionalController, |
||
130 | 'RepeatOrderModifier', |
||
131 | $fields, |
||
132 | $actions, |
||
133 | $optionalValidator |
||
134 | ); |
||
135 | } |
||
136 | |||
189 |
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.