Conditions | 1 |
Paths | 1 |
Total Lines | 103 |
Code Lines | 72 |
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 |
||
59 | public function updateCMSFields(FieldList $fields) |
||
60 | { |
||
61 | // Postage Options |
||
62 | $country_html = "<div class=\"field\">"; |
||
63 | $country_html .= "<p>First select valid countries using the 2 character "; |
||
64 | $country_html .= "shortcode (see http://fasteri.com/list/2/short-names-of-countries-and-iso-3166-codes).</p>"; |
||
65 | $country_html .= "<p>You can add multiple countries seperating them with"; |
||
66 | $country_html .= "a comma or use a '*' for all countries.</p>"; |
||
67 | $country_html .= "</div><br/>"; |
||
68 | |||
69 | $country_html_field = LiteralField::create("CountryDescription", $country_html); |
||
70 | |||
71 | $postage_fields = ToggleCompositeField::create( |
||
72 | 'PostageSettings', |
||
73 | _t("Orders.PostageSettings", "Postage Settings"), |
||
74 | [ |
||
75 | $country_html_field, |
||
76 | GridField::create( |
||
77 | 'PostageAreas', |
||
78 | '', |
||
79 | $this->owner->PostageAreas() |
||
80 | )->setConfig(GridFieldConfig_RecordEditor::create()) |
||
81 | ] |
||
82 | ); |
||
83 | |||
84 | // Discount options |
||
85 | $discount_fields = ToggleCompositeField::create( |
||
86 | 'DiscountSettings', |
||
87 | _t("Orders.DiscountSettings", "Discount Settings"), |
||
88 | [ |
||
89 | LiteralField::create("DiscountPadding", "<br/>"), |
||
90 | GridField::create( |
||
91 | 'Discounts', |
||
92 | '', |
||
93 | $this->owner->Discounts() |
||
94 | )->setConfig(GridFieldConfig_RecordEditor::create()) |
||
95 | ] |
||
96 | ); |
||
97 | |||
98 | // Order Notifications |
||
99 | $notification_fields = ToggleCompositeField::create( |
||
100 | 'OrderNotificationSettings', |
||
101 | _t("Orders.OrderNotificationSettings", "Order Notification Settings"), |
||
102 | [ |
||
103 | LiteralField::create("NotificationPadding", "<br/>"), |
||
104 | GridField::create( |
||
105 | "OrderNotifications", |
||
106 | "Order status notifications", |
||
107 | $this->owner->OrderNotifications() |
||
108 | )->setConfig(GridFieldConfig_RecordEditor::create()) |
||
109 | ] |
||
110 | ); |
||
111 | |||
112 | // Invoice Customisation |
||
113 | $invoice_customisation_fields = ToggleCompositeField::create( |
||
114 | 'InvoiceQuoteCustomSettings', |
||
115 | _t("Orders.InvoiceQuoteCustomisation", "Invoice and Quote Customisation"), |
||
116 | [ |
||
117 | UploadField::create('EstimateInvoiceLogo'), |
||
118 | TextField::create( |
||
119 | 'EstimateNumberPrefix', |
||
120 | _t("Orders.EstimatePrefix", "Add prefix to estimate numbers"), |
||
121 | null, |
||
122 | 9 |
||
123 | )->setAttribute( |
||
124 | "placeholder", |
||
125 | _t("Orders.OrderPrefixPlaceholder", "EG 'uk-123'") |
||
126 | ), |
||
127 | TextField::create( |
||
128 | 'InvoiceNumberPrefix', |
||
129 | _t("Orders.InvoicePrefix", "Add prefix to invoice numbers"), |
||
130 | null, |
||
131 | 9 |
||
132 | )->setAttribute( |
||
133 | "placeholder", |
||
134 | _t("Orders.OrderPrefixPlaceholder", "EG 'es-123'") |
||
135 | ), |
||
136 | NumericField::create( |
||
137 | "OrderNumberLength", |
||
138 | $this->owner->fieldLabel("OrderNumberLength") |
||
139 | )->setDescription(_t( |
||
140 | "Orders.OrderNumberLengthDescription", |
||
141 | "The default length invoice/estimate numbers are padded to" |
||
142 | )), |
||
143 | HTMLEditorField::create("InvoiceHeaderContent") |
||
144 | ->addExtraClass("stacked"), |
||
145 | HTMLEditorField::create("InvoiceFooterContent") |
||
146 | ->addExtraClass("stacked"), |
||
147 | HTMLEditorField::create("EstimateHeaderContent") |
||
148 | ->addExtraClass("stacked"), |
||
149 | HTMLEditorField::create("EstimateFooterContent") |
||
150 | ->addExtraClass("stacked") |
||
151 | ] |
||
152 | ); |
||
153 | |||
154 | // Add config sets |
||
155 | $fields->addFieldsToTab( |
||
156 | 'Root.Shop', |
||
157 | [ |
||
158 | $postage_fields, |
||
159 | $discount_fields, |
||
160 | $notification_fields, |
||
161 | $invoice_customisation_fields |
||
162 | ] |
||
173 |