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