| Conditions | 5 |
| Paths | 6 |
| Total Lines | 82 |
| Code Lines | 51 |
| Lines | 0 |
| Ratio | 0 % |
| 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 |
||
| 53 | public function getEditForm($id = null, $fields = null) |
||
| 54 | { |
||
| 55 | if (!$id) { |
||
| 56 | $id = $this->currentPageID(); |
||
| 57 | } |
||
| 58 | |||
| 59 | $form = parent::getEditForm($id); |
||
| 60 | $record = $this->getRecord($id); |
||
| 61 | |||
| 62 | if ($record && !$record->canView()) { |
||
| 63 | return Security::permissionFailure($this); |
||
| 64 | } |
||
| 65 | |||
| 66 | $newComments = Comment::get()->filter('Moderated', 0); |
||
| 67 | |||
| 68 | $newGrid = new CommentsGridField( |
||
| 69 | 'NewComments', |
||
| 70 | _t('CommentsAdmin.NewComments', 'New'), |
||
| 71 | $newComments, |
||
| 72 | CommentsGridFieldConfig::create() |
||
| 73 | ); |
||
| 74 | |||
| 75 | $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); |
||
| 76 | |||
| 77 | $approvedGrid = new CommentsGridField( |
||
| 78 | 'ApprovedComments', |
||
| 79 | _t('CommentsAdmin.ApprovedComments', 'Approved'), |
||
| 80 | $approvedComments, |
||
| 81 | CommentsGridFieldConfig::create() |
||
| 82 | ); |
||
| 83 | |||
| 84 | $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); |
||
| 85 | |||
| 86 | $spamGrid = new CommentsGridField( |
||
| 87 | 'SpamComments', |
||
| 88 | _t('CommentsAdmin.SpamComments', 'Spam'), |
||
| 89 | $spamComments, |
||
| 90 | CommentsGridFieldConfig::create() |
||
| 91 | ); |
||
| 92 | |||
| 93 | $newCount = '(' . count($newComments) . ')'; |
||
| 94 | $approvedCount = '(' . count($approvedComments) . ')'; |
||
| 95 | $spamCount = '(' . count($spamComments) . ')'; |
||
| 96 | |||
| 97 | $fields = new FieldList( |
||
| 98 | $root = new TabSet( |
||
| 99 | 'Root', |
||
| 100 | new Tab('NewComments', _t('CommentAdmin.NewComments', 'New') . ' ' . $newCount, |
||
| 101 | $newGrid |
||
| 102 | ), |
||
| 103 | new Tab('ApprovedComments', _t('CommentAdmin.ApprovedComments', 'Approved') . ' ' . $approvedCount, |
||
| 104 | $approvedGrid |
||
| 105 | ), |
||
| 106 | new Tab('SpamComments', _t('CommentAdmin.SpamComments', 'Spam') . ' ' . $spamCount, |
||
| 107 | $spamGrid |
||
| 108 | ) |
||
| 109 | ) |
||
| 110 | ); |
||
| 111 | |||
| 112 | $root->setTemplate('CMSTabSet'); |
||
| 113 | |||
| 114 | $actions = new FieldList(); |
||
| 115 | |||
| 116 | $form = new Form( |
||
| 117 | $this, |
||
| 118 | 'EditForm', |
||
| 119 | $fields, |
||
| 120 | $actions |
||
| 121 | ); |
||
| 122 | |||
| 123 | $form->addExtraClass('cms-edit-form'); |
||
| 124 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
| 125 | |||
| 126 | if ($form->Fields()->hasTabset()) { |
||
| 127 | $form->Fields()->findOrMakeTab('Root')->setTemplate('CMSTabSet'); |
||
| 128 | $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); |
||
| 129 | } |
||
| 130 | |||
| 131 | $this->extend('updateEditForm', $form); |
||
| 132 | |||
| 133 | return $form; |
||
| 134 | } |
||
| 135 | } |
||
| 136 |
This check marks private properties in classes that are never used. Those properties can be removed.