Conditions | 10 |
Paths | 96 |
Total Lines | 146 |
Code Lines | 101 |
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 |
||
101 | public function getCMSFields() |
||
102 | { |
||
103 | $fields = parent::getCMSFields(); |
||
104 | |||
105 | $emailsSentField = $fields->dataFieldByName('EmailsSent'); |
||
106 | $fields->removeFieldFromTab('Root', 'EmailsSent'); |
||
107 | |||
108 | $fields->addFieldToTab( |
||
109 | 'Root.Main', |
||
110 | CheckboxField::create('Disable') |
||
111 | ); |
||
112 | $fields->addFieldToTab( |
||
113 | 'Root.Main', |
||
114 | $dataObjecField = DropdownField::create( |
||
115 | 'DataObject', |
||
116 | 'Table/Class Name', |
||
117 | $this->dataObjectOptions() |
||
118 | ) |
||
119 | ->setRightTitle('Type a valid table/class name') |
||
120 | ); |
||
121 | if ($this->Config()->get('default_data_object')) { |
||
122 | $fields->replaceField('DataObject', $dataObjecField->performReadonlyTransformation()); |
||
123 | } |
||
124 | |||
125 | |||
126 | |||
127 | $fields->addFieldToTab( |
||
128 | 'Root.Main', |
||
129 | $emailFieldField = DropdownField::create( |
||
130 | 'EmailField', |
||
131 | 'Email Field', |
||
132 | $this->emailFieldOptions() |
||
133 | ) |
||
134 | ->setRightTitle('Select the field that will contain a valid email address') |
||
135 | ->setEmptyString('[ Please select ]') |
||
136 | ); |
||
137 | if ($this->Config()->get('default_email_field')) { |
||
138 | $fields->replaceField('EmailField', $emailFieldField->performReadonlyTransformation()); |
||
139 | } |
||
140 | |||
141 | $fields->addFieldToTab( |
||
142 | 'Root.Main', |
||
143 | $dateFieldField = DropdownField::create( |
||
144 | 'DateField', |
||
145 | 'Date Field', |
||
146 | $this->dateFieldOptions() |
||
147 | ) |
||
148 | ->setRightTitle('Select a valid Date field to calculate when reminders should be sent') |
||
149 | ->setEmptyString('[ Please select ]') |
||
150 | ); |
||
151 | if ($this->Config()->get('default_date_field')) { |
||
152 | $fields->replaceField('DateField', $dateFieldField->performReadonlyTransformation()); |
||
153 | } |
||
154 | |||
155 | $fields->removeFieldsFromTab( |
||
156 | 'Root.Main', |
||
157 | array('Days', 'BeforeAfter', 'RepeatDays') |
||
158 | ); |
||
159 | $fields->addFieldsToTab( |
||
160 | 'Root.Main', |
||
161 | array( |
||
162 | DropdownField::create('BeforeAfter', 'Before / After Expiration', array('before' => 'before', 'after' => 'after', 'immediately' => 'immediately')) |
||
163 | ->setRightTitle('Are the days listed above before or after the actual expiration date.'), |
||
164 | NumericField::create('Days', 'Days') |
||
165 | ->setRightTitle('How many days in advance (before) or in arrears (after) of the expiration date should this email be sent? </br>This field is ignored if set to send immediately.'), |
||
166 | NumericField::create('RepeatDays', 'Repeat Cycle Days') |
||
167 | ->setRightTitle( |
||
168 | ' |
||
169 | Number of days after which the same reminder can be sent to the same email address. |
||
170 | <br />We allow an e-mail to be sent to one specific email address for one specific reminder only once. |
||
171 | <br />In this field you can indicate for how long we will apply this rule.' |
||
172 | ) |
||
173 | ) |
||
174 | ); |
||
175 | $fields->addFieldsToTab( |
||
176 | 'Root.EmailContent', |
||
177 | array( |
||
178 | TextField::create('EmailFrom', 'Email From Address') |
||
179 | ->setRightTitle('The email from address, eg: "My Company <[email protected]>"'), |
||
180 | $subjectField = TextField::create('EmailSubject', 'Email Subject Line') |
||
181 | ->setRightTitle('The subject of the email'), |
||
182 | $contentField = HTMLEditorField::create('Content', 'Email Content') |
||
183 | ->SetRows(20) |
||
184 | ) |
||
185 | ); |
||
186 | if ($obj = $this->getReplacerObject()) { |
||
187 | $html = $obj->replaceHelpList($asHTML = true); |
||
188 | $otherFieldsThatCanBeUsed = $this->getFieldsFromDataObject(array('*')); |
||
189 | $replaceableFields = $this->Config()->get('replaceable_record_fields'); |
||
190 | if (count($otherFieldsThatCanBeUsed)) { |
||
191 | $html .= '<h3>You can also use the record fields (not replaced in tests):</h3><ul>'; |
||
192 | foreach ($otherFieldsThatCanBeUsed as $key => $value) { |
||
193 | if (in_array($key, $replaceableFields)) { |
||
194 | $html .= '<li><strong>$'.$key.'</strong> <span>'.$value.'</span></li>'; |
||
195 | } |
||
196 | } |
||
197 | } |
||
198 | $html .= '</ul>'; |
||
199 | $subjectField->setRightTitle('for replacement options, please see below ...'); |
||
200 | $contentField->setRightTitle($html); |
||
201 | } |
||
202 | $fields->addFieldsToTab( |
||
203 | 'Root.Sent', |
||
204 | array( |
||
205 | TextareaField::create('SendTestTo', 'Send test email to ...') |
||
206 | ->setRightTitle( |
||
207 | ' |
||
208 | Separate emails by commas, a test email will be sent every time you save this Email Reminder, if you do not want test emails to be sent make sure this field is empty |
||
209 | ' |
||
210 | ) |
||
211 | ->SetRows(3) |
||
212 | ) |
||
213 | ); |
||
214 | if ($emailsSentField) { |
||
215 | $config = $emailsSentField->getConfig(); |
||
216 | $config->removeComponentsByType('GridFieldAddExistingAutocompleter'); |
||
217 | $fields->addFieldToTab( |
||
218 | 'Root.Sent', |
||
219 | $emailsSentField |
||
220 | ); |
||
221 | } |
||
222 | $records = $this->CurrentRecords(); |
||
223 | if ($records) { |
||
224 | $fields->addFieldsToTab( |
||
225 | 'Root.Review', |
||
226 | array( |
||
227 | GridField::create( |
||
228 | 'CurrentRecords', |
||
229 | 'Today we are sending to ...', |
||
230 | $records |
||
231 | ), |
||
232 | LiteralField::create( |
||
233 | 'SampleSelectStatement', |
||
234 | '<h3>Here is a sample statement used to select records:</h3> |
||
235 | <pre>'.$this->whereStatementForDays().'</pre>' |
||
236 | ), |
||
237 | LiteralField::create( |
||
238 | 'SampleFieldDataForRecords', |
||
239 | '<h3>sample of '.$this->DateField.' field values:</h3> |
||
240 | <li>'.implode('</li><li>', $this->SampleFieldDataForRecords()).'</li>' |
||
241 | ) |
||
242 | ) |
||
243 | ); |
||
244 | } |
||
245 | return $fields; |
||
246 | } |
||
247 | |||
542 |
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.