Conditions | 10 |
Paths | 14 |
Total Lines | 95 |
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 |
||
27 | public function getModifierForm(Controller $optionalController = NULL, Validator $optionalValidator = NULL) |
||
28 | { |
||
29 | $fields = FieldList::create(); |
||
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 | if ($repeatOrder && $currentMember) { |
||
44 | |||
45 | $updateLink = RepeatOrdersPage::get_repeat_order_link('modify', $repeatOrder->ID); |
||
46 | $cancelLink = RepeatOrdersPage::get_repeat_order_link('cancel', $repeatOrder->ID); |
||
|
|||
47 | |||
48 | if ($repeatOrder->canModify()) { |
||
49 | $fields->push( |
||
50 | LiteralField::create( |
||
51 | 'modifyRepeatOrder', |
||
52 | <<<HTML |
||
53 | <div class="Actions"> |
||
54 | <input id="ModifyRepeatOrderUpdate" class="action" type="button" value="Edit your associated Repeat Order" onclick="window.location='{$updateLink}';" /> |
||
55 | </div> |
||
56 | HTML |
||
57 | ) |
||
58 | ); |
||
59 | } else { |
||
60 | $fields->push( |
||
61 | LiteralField::create( |
||
62 | 'createRepeatOrder', |
||
63 | <<<HTML |
||
64 | <div class="Actions"> |
||
65 | <input id="ModifyRepeatOrderCreate" class="action" type="button" value="Create a new Repeat Order" onclick="window.location='{$createLink}';" /> |
||
66 | </div> |
||
67 | HTML |
||
68 | ) |
||
69 | ); |
||
70 | } |
||
71 | Requirements::customScript("jQuery(document).ready(function(){jQuery(\"input[name='action_processOrder']\").hide();});", "hide_action_processOrder"); |
||
72 | } elseif ($currentMember) { |
||
73 | if ($order->RepeatOrderID) { |
||
74 | $fields->push( |
||
75 | LiteralField::create( |
||
76 | "whatAreRepeatOrders", |
||
77 | <<<HTML |
||
78 | <div id="WhatAreRepeatOrders">This order is based on a Repeat Order.</div> |
||
79 | HTML |
||
80 | )); |
||
81 | } else { |
||
82 | $fields->push( |
||
83 | LiteralField::create( |
||
84 | 'createRepeatOrder', |
||
85 | <<<HTML |
||
86 | <div class="Actions"> |
||
87 | <input id="ModifyRepeatOrderCreate" class="action" type="button" value="Turn this Order into a Repeat Order" onclick="window.location='{$createLink}';" /> |
||
88 | </div> |
||
89 | HTML |
||
90 | ) |
||
91 | ); |
||
92 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
93 | if ($page) { |
||
94 | $fields->push( |
||
95 | LiteralField::create("whatAreRepeatOrders", |
||
96 | <<<HTML |
||
97 | <div id="WhatAreRepeatOrders">$page->WhatAreRepeatOrders</div> |
||
98 | HTML |
||
99 | )); |
||
100 | } |
||
101 | } |
||
102 | } else { |
||
103 | $page = DataObject::get_one("RepeatOrdersPage"); |
||
104 | if ($page) { |
||
105 | $fields->push( |
||
106 | LiteralField::create( |
||
107 | "whatAreRepeatOrders", |
||
108 | <<<HTML |
||
109 | <div id="WhatAreRepeatOrders">$page->OnceLoggedInYouCanCreateRepeatOrder</div> |
||
110 | HTML |
||
111 | )); |
||
112 | } |
||
113 | } |
||
114 | return RepeatOrderModifierForm::create( |
||
115 | $optionalController, |
||
116 | 'RepeatOrderModifier', |
||
117 | $fields, |
||
118 | $actions = FieldList::create(), |
||
119 | $optionalValidator |
||
120 | ); |
||
121 | } |
||
122 | |||
175 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.