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