| Conditions | 5 |
| Paths | 16 |
| Total Lines | 56 |
| Code Lines | 33 |
| Lines | 14 |
| Ratio | 25 % |
| 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 |
||
| 78 | public function updateCMSFields(FieldList $fields) |
||
| 79 | { |
||
| 80 | $ticketLabel = _t('TicketExtension.Tickets', 'Tickets'); |
||
| 81 | $fields->addFieldsToTab( |
||
| 82 | "Root.$ticketLabel", array( |
||
| 83 | GridField::create('Tickets', $ticketLabel, $this->owner->Tickets(), $ticketsGridFieldConfig = GridFieldConfig_RecordEditor::create()), |
||
|
1 ignored issue
–
show
|
|||
| 84 | NumericField::create('Capacity', _t('TicketExtension.Capacity', 'Capacity')), |
||
| 85 | NumericField::create('OrderMin', _t('TicketExtension.OrderMin', 'Minimum amount of tickets required per reservation')), |
||
| 86 | NumericField::create('OrderMax', _t('TicketExtension.OrderMax', 'Maximum amount of tickets allowed per reservation')), |
||
| 87 | HtmlEditorField::create('SuccessMessage', _t('TicketExtension.SuccessMessage', 'Success message'))->setRows(4), |
||
| 88 | HtmlEditorField::create('SuccessMessageMail', _t('TicketExtension.MailMessage', 'Mail message'))->setRows(4) |
||
| 89 | )); |
||
| 90 | |||
| 91 | // If the event dates are in the past remove ability to create new tickets, reservations and attendees. |
||
| 92 | // This is done here instead of in the canCreate method because of the lack of context there. |
||
| 93 | if (!$this->canCreateTickets()) { |
||
| 94 | $ticketsGridFieldConfig->removeComponentsByType(new GridFieldAddNewButton()); |
||
| 95 | } |
||
| 96 | |||
| 97 | // Create Reservations tab |
||
| 98 | View Code Duplication | if ($this->owner->Reservations()->exists()) { |
|
| 99 | $reservationLabel = _t('TicketExtension.Reservations', 'Reservations'); |
||
| 100 | $fields->addFieldToTab( |
||
| 101 | "Root.$reservationLabel", |
||
| 102 | GridField::create('Reservations', $reservationLabel, $this->owner->Reservations(), GridFieldConfig_RecordEditor::create()) |
||
|
1 ignored issue
–
show
|
|||
| 103 | ); |
||
| 104 | } |
||
| 105 | |||
| 106 | // Create Attendees tab |
||
| 107 | if ($this->owner->Attendees()->exists()) { |
||
| 108 | $guestListLabel = _t('TicketExtension.GuestList', 'GuestList'); |
||
| 109 | $fields->addFieldToTab( |
||
| 110 | "Root.$guestListLabel", |
||
| 111 | GridField::create('Attendees', $guestListLabel, $this->owner->Attendees(), $attendeesGridFieldConfig = GridFieldConfig_RecordEditor::create()) |
||
|
1 ignored issue
–
show
|
|||
| 112 | ); |
||
| 113 | $attendeesGridFieldConfig->addComponent(new GuestListExportButton($this->owner, 'Footer')); |
||
| 114 | } |
||
| 115 | |||
| 116 | // Create WaitingList tab |
||
| 117 | View Code Duplication | if ($this->owner->WaitingList()->exists()) { |
|
|
1 ignored issue
–
show
|
|||
| 118 | $waitingListLabel = _t('TicketExtension.WaitingList', 'WaitingList'); |
||
| 119 | $fields->addFieldToTab( |
||
| 120 | "Root.$waitingListLabel", |
||
| 121 | GridField::create('WaitingList', $waitingListLabel, $this->owner->WaitingList(), GridFieldConfig_RecordEditor::create()) |
||
|
1 ignored issue
–
show
|
|||
| 122 | ); |
||
| 123 | } |
||
| 124 | |||
| 125 | // Create Fields tab |
||
| 126 | $extraFieldsLabel = _t('TicketExtension.ExtraFields', 'Attendee fields'); |
||
| 127 | $fields->addFieldToTab( |
||
| 128 | "Root.$extraFieldsLabel", |
||
| 129 | GridField::create('WaitingList', $extraFieldsLabel, $this->owner->Fields(), GridFieldConfig_Fields::create()) |
||
|
1 ignored issue
–
show
|
|||
| 130 | ); |
||
| 131 | |||
| 132 | $this->owner->extend('updateTicketExtensionFields', $fields); |
||
| 133 | } |
||
| 134 | |||
| 268 |
This check marks private properties in classes that are never used. Those properties can be removed.