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