| Conditions | 5 |
| Paths | 16 |
| Total Lines | 53 |
| Code Lines | 32 |
| Lines | 21 |
| Ratio | 39.62 % |
| 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 |
||
| 64 | public function updateCMSFields(FieldList $fields) |
||
| 65 | { |
||
| 66 | $gridFieldConfig = GridFieldConfig_RecordEditor::create(); |
||
| 67 | |||
| 68 | // If the event dates are in the past remove ability to create new tickets, reservations and attendees. |
||
| 69 | // This is done here instead of in the canCreate method because of the lack of context there. |
||
| 70 | if (!$this->canCreateTickets()) { |
||
| 71 | $gridFieldConfig->removeComponentsByType(new GridFieldAddNewButton()); |
||
| 72 | } |
||
| 73 | |||
| 74 | $ticketLabel = _t('TicketExtension.Tickets', 'Tickets'); |
||
| 75 | $fields->addFieldsToTab( |
||
| 76 | "Root.$ticketLabel", array( |
||
| 77 | GridField::create('Tickets', $ticketLabel, $this->owner->Tickets(), $gridFieldConfig), |
||
|
1 ignored issue
–
show
|
|||
| 78 | NumericField::create('Capacity', _t('TicketExtension.Capacity', 'Capacity')), |
||
| 79 | HtmlEditorField::create('SuccessMessage', |
||
| 80 | _t('TicketExtension.SuccessMessage', 'Success message'))->setRows(4), |
||
| 81 | HtmlEditorField::create('SuccessMessageMail', _t('TicketExtension.MailMessage', 'Mail message'))->setRows(4) |
||
| 82 | )); |
||
| 83 | |||
| 84 | View Code Duplication | if ($this->owner->Reservations()->exists()) { |
|
| 85 | $reservationLabel = _t('TicketExtension.Reservations', 'Reservations'); |
||
| 86 | $fields->addFieldToTab( |
||
| 87 | "Root.$reservationLabel", |
||
| 88 | GridField::create('Reservations', $reservationLabel, $this->owner->Reservations(), $gridFieldConfig) |
||
|
1 ignored issue
–
show
|
|||
| 89 | ); |
||
| 90 | } |
||
| 91 | |||
| 92 | View Code Duplication | if ($this->owner->Attendees()->exists()) { |
|
|
1 ignored issue
–
show
|
|||
| 93 | $guestListLabel = _t('TicketExtension.GuestList', 'GuestList'); |
||
| 94 | $fields->addFieldToTab( |
||
| 95 | "Root.$guestListLabel", |
||
| 96 | GridField::create('Attendees', $guestListLabel, $this->owner->Attendees(), $gridFieldConfig) |
||
|
1 ignored issue
–
show
|
|||
| 97 | ); |
||
| 98 | } |
||
| 99 | |||
| 100 | View Code Duplication | if ($this->owner->WaitingList()->exists()) { |
|
|
1 ignored issue
–
show
|
|||
| 101 | $waitingListLabel = _t('TicketExtension.WaitingList', 'WaitingList'); |
||
| 102 | $fields->addFieldToTab( |
||
| 103 | "Root.$waitingListLabel", |
||
| 104 | GridField::create('WaitingList', $waitingListLabel, $this->owner->WaitingList(), $gridFieldConfig) |
||
|
1 ignored issue
–
show
|
|||
| 105 | ); |
||
| 106 | } |
||
| 107 | |||
| 108 | |||
| 109 | $extraFieldsLabel = _t('TicketExtension.ExtraFields', 'Attendee fields'); |
||
| 110 | $fields->addFieldToTab( |
||
| 111 | "Root.$extraFieldsLabel", |
||
| 112 | GridField::create('WaitingList', $extraFieldsLabel, $this->owner->Fields(), |
||
|
1 ignored issue
–
show
|
|||
| 113 | GridFieldConfig_Fields::create()) |
||
| 114 | ); |
||
| 115 | |||
| 116 | } |
||
| 117 | |||
| 237 |
This check marks private properties in classes that are never used. Those properties can be removed.