Conditions | 8 |
Paths | 24 |
Total Lines | 86 |
Code Lines | 61 |
Lines | 38 |
Ratio | 44.19 % |
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 |
||
118 | public function getCMSFields() |
||
119 | { |
||
120 | $fields = parent::getCMSFields(); |
||
121 | $fields->insertBefore(ReadonlyField::create('Created'), 'Note'); |
||
122 | $fields->insertBefore(ReadonlyField::create('LastEdited'), 'Note'); |
||
123 | $fieldLabels = $this->fieldLabels(); |
||
124 | $fields->removeByName('UpdateNoteRecordClass'); |
||
125 | $fields->removeByName('UpdateNoteRecordID'); |
||
126 | |||
127 | $otherFieldsToRemove = $this->Config()->get('fields_to_remove_in_the_cms_fields'); |
||
128 | foreach ($otherFieldsToRemove as $field) { |
||
129 | $fields->removeByName($field); |
||
130 | // code... |
||
131 | } |
||
132 | $fields->insertBefore( |
||
133 | ReadonlyField::create( |
||
134 | 'Created' |
||
135 | ), |
||
136 | 'Note' |
||
137 | ); |
||
138 | $fields->insertBefore( |
||
139 | ReadonlyField::create( |
||
140 | 'LastEdited' |
||
141 | ), |
||
142 | 'Note' |
||
143 | ); |
||
144 | if ($whoField = $fields->dataFieldByName('UpdatedByID')) { |
||
145 | $fields->removeFieldFromTab('Root.Main', 'UpdatedByID'); |
||
146 | $who = $this->UpdatedBy(); |
||
147 | if ($who && $who->exists()) { |
||
148 | View Code Duplication | if ($who->hasMethod('CMSEditLink')) { |
|
149 | $fields->addFieldToTab( |
||
150 | 'Root.Main', |
||
151 | $whoField = ReadonlyField::create( |
||
152 | 'UpdatedByLink', |
||
153 | $fieldLabels['UpdatedBy'], |
||
154 | '<h2><a href="'.$who->CMSEditLink().'" target="_blank">'.$who->getTitle().'</a></h2>' |
||
155 | ) |
||
156 | ); |
||
157 | } else { |
||
158 | $fields->addFieldToTab( |
||
159 | 'Root.Main', |
||
160 | $whoField = ReadonlyField::create( |
||
161 | 'UpdatedByLink', |
||
162 | $fieldLabels['UpdatedBy'], |
||
163 | '<h2>'.$who->getTitle().'.</h2>' |
||
164 | ) |
||
165 | ); |
||
166 | } |
||
167 | } else { |
||
168 | $fields->addFieldToTab( |
||
169 | 'Root.Main', |
||
170 | $whoField = ReadonlyField::create( |
||
171 | 'UpdatedByLink', |
||
172 | $fieldLabels['UpdatedBy'], |
||
173 | '<p class="message warning">no editor found</p>' |
||
174 | ) |
||
175 | ); |
||
176 | } |
||
177 | $whoField->dontEscape = true; |
||
178 | } |
||
179 | |||
180 | if ($parent = $this->getParent()) { |
||
181 | View Code Duplication | if ($parent->hasMethod('CMSEditLink')) { |
|
182 | $fields->addFieldToTab( |
||
183 | 'Root.Main', |
||
184 | $parentField = ReadonlyField::create( |
||
185 | 'ParentLink', |
||
186 | $fieldLabels['UpdateNoteRecord'], |
||
187 | '<h2><a href="'.$parent->CMSEditLink().'" target="_blank">'.$parent->getTitle().'</a></h2>' |
||
188 | ) |
||
189 | ); |
||
190 | } else { |
||
191 | $fields->addFieldToTab( |
||
192 | 'Root.Main', |
||
193 | $parentField = ReadonlyField::create( |
||
194 | 'ParentLink', |
||
195 | $fieldLabels['UpdateNoteRecord'], |
||
196 | '<h2>'.$parent->getTitle().'</h2>' |
||
197 | ) |
||
198 | ); |
||
199 | } |
||
200 | $parentField->dontEscape = true; |
||
201 | } |
||
202 | return $fields; |
||
203 | } |
||
204 | |||
301 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.