| Conditions | 4 |
| Paths | 4 |
| Total Lines | 92 |
| Code Lines | 57 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 4 | ||
| Bugs | 0 | Features | 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 |
||
| 201 | public function getCMSFields() |
||
| 202 | { |
||
| 203 | $fields = parent::getCMSFields(); |
||
| 204 | $fields->removeByName( |
||
| 205 | [ |
||
| 206 | 'SendCode', |
||
| 207 | 'SendNow', |
||
| 208 | 'ResponseCode', |
||
| 209 | 'Sent', |
||
| 210 | 'Data', |
||
| 211 | 'EditorID', |
||
| 212 | ] |
||
| 213 | ); |
||
| 214 | if ($this->exists()) { |
||
| 215 | $fields->removeByName( |
||
| 216 | [ |
||
| 217 | 'HealthCheckItemProviders', |
||
| 218 | ] |
||
| 219 | ); |
||
| 220 | if ($this->Sent) { |
||
| 221 | $viewLink = $this->ViewLink(); |
||
| 222 | if ($viewLink) { |
||
| 223 | $fields->addFieldsToTab( |
||
| 224 | 'Root.Main', |
||
| 225 | [ |
||
| 226 | HTMLReadonlyField::create( |
||
| 227 | 'Link', |
||
| 228 | 'Open report', |
||
| 229 | '<a href="' . $viewLink . '">View Link</a>' |
||
| 230 | ), |
||
| 231 | ] |
||
| 232 | ); |
||
| 233 | } |
||
| 234 | } else { |
||
| 235 | $fields->removeByName( |
||
| 236 | [ |
||
| 237 | 'HasError', |
||
| 238 | ] |
||
| 239 | ); |
||
| 240 | $fields->addFieldsToTab( |
||
| 241 | 'Root.Main', |
||
| 242 | [ |
||
| 243 | CheckboxSetField::create( |
||
| 244 | 'HealthCheckItemProviders', |
||
| 245 | 'Data Points to be Provided', |
||
| 246 | HealthCheckItemProvider::get()->filter(['Include' => true])->map('ID', 'CodeNice') |
||
| 247 | )->setDescription('Please untick any data that you prefer not to provide.'), |
||
| 248 | ] |
||
| 249 | ); |
||
| 250 | } |
||
| 251 | $fields->addFieldsToTab( |
||
| 252 | 'Root.Main', |
||
| 253 | [ |
||
| 254 | TextField::create('MainUrl', 'Main URL'), |
||
| 255 | TextField::create('MainUrl', 'Main URL'), |
||
| 256 | TextField::create('OtherUrls', 'Other Urls') |
||
| 257 | ->setDescription('Separate by comma - e.g. new.mysite.com, otherurl.com, etc ...'), |
||
| 258 | ReadonlyField::create('HasBeenSent', 'Sent', $this->dbObject('Sent')->Nice()), |
||
| 259 | ReadonlyField::create('Editor Email', 'Editor Email', $this->Editor()->Email), |
||
| 260 | ReadonlyField::create('LastEdited'), |
||
| 261 | ] |
||
| 262 | ); |
||
| 263 | $fields->addFieldsToTab( |
||
| 264 | 'Root.Output', |
||
| 265 | [ |
||
| 266 | ReadonlyField::create('SendCode'), |
||
| 267 | ReadonlyField::create('ResponseCode'), |
||
| 268 | LiteralField::create( |
||
| 269 | 'Output', |
||
| 270 | '<h2>Data</h2><pre>' . json_encode(json_decode($this->Data), JSON_PRETTY_PRINT) . '</pre>' |
||
| 271 | ), |
||
| 272 | ] |
||
| 273 | ); |
||
| 274 | $fields->addFieldsToTab( |
||
| 275 | 'Root.PiecesOfInfo', |
||
| 276 | [ |
||
| 277 | GridField::create( |
||
| 278 | 'HealthCheckItemProvidersList', |
||
| 279 | 'Data List', |
||
| 280 | HealthCheckItemProvider::get(), |
||
| 281 | GridFieldConfig_RecordEditor::create() |
||
| 282 | ), |
||
| 283 | ] |
||
| 284 | ); |
||
| 285 | } else { |
||
| 286 | $fields->removeByName( |
||
| 287 | [ |
||
| 288 | 'HasError', |
||
| 289 | ] |
||
| 290 | ); |
||
| 291 | } |
||
| 292 | return $fields; |
||
| 293 | } |
||
| 367 |