| Conditions | 5 | 
| Paths | 6 | 
| Total Lines | 82 | 
| Code Lines | 51 | 
| Lines | 0 | 
| Ratio | 0 % | 
| Changes | 8 | ||
| Bugs | 3 | Features | 2 | 
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 | ||
| 41 | public function getEditForm($id = null, $fields = null) | ||
| 42 |     { | ||
| 43 |         if (!$id) { | ||
| 44 | $id = $this->currentPageID(); | ||
| 45 | } | ||
| 46 | |||
| 47 | $form = parent::getEditForm($id); | ||
| 48 | $record = $this->getRecord($id); | ||
| 49 | |||
| 50 |         if ($record && !$record->canView()) { | ||
| 51 | return Security::permissionFailure($this); | ||
| 52 | } | ||
| 53 | |||
| 54 |         $newComments = Comment::get()->filter('Moderated', 0); | ||
| 55 | |||
| 56 | $newGrid = new CommentsGridField( | ||
| 57 | 'NewComments', | ||
| 58 |             _t('CommentsAdmin.NewComments', 'New'), | ||
| 59 | $newComments, | ||
| 60 | CommentsGridFieldConfig::create() | ||
| 61 | ); | ||
| 62 | |||
| 63 |         $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); | ||
| 64 | |||
| 65 | $approvedGrid = new CommentsGridField( | ||
| 66 | 'ApprovedComments', | ||
| 67 |             _t('CommentsAdmin.ApprovedComments', 'Approved'), | ||
| 68 | $approvedComments, | ||
| 69 | CommentsGridFieldConfig::create() | ||
| 70 | ); | ||
| 71 | |||
| 72 |         $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); | ||
| 73 | |||
| 74 | $spamGrid = new CommentsGridField( | ||
| 75 | 'SpamComments', | ||
| 76 |             _t('CommentsAdmin.SpamComments', 'Spam'), | ||
| 77 | $spamComments, | ||
| 78 | CommentsGridFieldConfig::create() | ||
| 79 | ); | ||
| 80 | |||
| 81 |         $newCount = '(' . count($newComments) . ')'; | ||
| 82 |         $approvedCount = '(' . count($approvedComments) . ')'; | ||
| 83 |         $spamCount = '(' . count($spamComments) . ')'; | ||
| 84 | |||
| 85 | $fields = new FieldList( | ||
| 86 | $root = new TabSet( | ||
| 87 | 'Root', | ||
| 88 |                 new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount, | ||
| 89 | $newGrid | ||
| 90 | ), | ||
| 91 |                 new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount, | ||
| 92 | $approvedGrid | ||
| 93 | ), | ||
| 94 |                 new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount, | ||
| 95 | $spamGrid | ||
| 96 | ) | ||
| 97 | ) | ||
| 98 | ); | ||
| 99 | |||
| 100 |         $root->setTemplate('CMSTabSet'); | ||
| 101 | |||
| 102 | $actions = new FieldList(); | ||
| 103 | |||
| 104 | $form = new Form( | ||
| 105 | $this, | ||
| 106 | 'EditForm', | ||
| 107 | $fields, | ||
| 108 | $actions | ||
| 109 | ); | ||
| 110 | |||
| 111 |         $form->addExtraClass('cms-edit-form'); | ||
| 112 |         $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); | ||
| 113 | |||
| 114 |         if ($form->Fields()->hasTabset()) { | ||
| 115 |             $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); | ||
| 116 |             $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); | ||
| 117 | } | ||
| 118 | |||
| 119 |         $this->extend('updateEditForm', $form); | ||
| 120 | |||
| 121 | return $form; | ||
| 122 | } | ||
| 123 | } | ||
| 124 | 
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.