| Conditions | 5 |
| Paths | 6 |
| Total Lines | 93 |
| Code Lines | 61 |
| 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 |
||
| 55 | public function getEditForm($id = null, $fields = null) |
||
| 56 | { |
||
| 57 | if (!$id) { |
||
| 58 | $id = $this->currentPageID(); |
||
| 59 | } |
||
| 60 | |||
| 61 | $form = parent::getEditForm($id); |
||
| 62 | $record = $this->getRecord($id); |
||
| 63 | |||
| 64 | if ($record && !$record->canView()) { |
||
| 65 | return Security::permissionFailure($this); |
||
| 66 | } |
||
| 67 | |||
| 68 | $newComments = Comment::get()->filter('Moderated', 0); |
||
| 69 | |||
| 70 | $newGrid = CommentsGridField::create( |
||
| 71 | 'NewComments', |
||
| 72 | '', |
||
| 73 | $newComments, |
||
| 74 | CommentsGridFieldConfig::create() |
||
| 75 | ); |
||
| 76 | |||
| 77 | $approvedComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 0); |
||
| 78 | |||
| 79 | $approvedGrid = CommentsGridField::create( |
||
| 80 | 'ApprovedComments', |
||
| 81 | '', |
||
| 82 | $approvedComments, |
||
| 83 | CommentsGridFieldConfig::create() |
||
| 84 | ); |
||
| 85 | |||
| 86 | $spamComments = Comment::get()->filter('Moderated', 1)->filter('IsSpam', 1); |
||
| 87 | |||
| 88 | $spamGrid = CommentsGridField::create( |
||
| 89 | 'SpamComments', |
||
| 90 | '', |
||
| 91 | $spamComments, |
||
| 92 | CommentsGridFieldConfig::create() |
||
| 93 | ); |
||
| 94 | |||
| 95 | $fields = FieldList::create( |
||
| 96 | $root = TabSet::create( |
||
| 97 | 'Root', |
||
| 98 | Tab::create( |
||
| 99 | 'NewComments', |
||
| 100 | _t( |
||
| 101 | __CLASS__.'.NewComments', |
||
| 102 | 'New ({count})', |
||
| 103 | ['count' => count($newComments)] |
||
| 104 | ), |
||
| 105 | $newGrid |
||
| 106 | ), |
||
| 107 | Tab::create( |
||
| 108 | 'ApprovedComments', |
||
| 109 | _t( |
||
| 110 | __CLASS__.'.ApprovedComments', |
||
| 111 | 'Approved ({count})', |
||
| 112 | ['count' => count($approvedComments)] |
||
| 113 | ), |
||
| 114 | $approvedGrid |
||
| 115 | ), |
||
| 116 | Tab::create( |
||
| 117 | 'SpamComments', |
||
| 118 | _t( |
||
| 119 | __CLASS__.'.SpamComments', |
||
| 120 | 'Spam ({count})', |
||
| 121 | ['count' => count($spamComments)] |
||
| 122 | ), |
||
| 123 | $spamGrid |
||
| 124 | ) |
||
| 125 | ) |
||
| 126 | ); |
||
| 127 | |||
| 128 | $actions = FieldList::create(); |
||
| 129 | |||
| 130 | $form = Form::create( |
||
| 131 | $this, |
||
| 132 | 'EditForm', |
||
| 133 | $fields, |
||
| 134 | $actions |
||
| 135 | ); |
||
| 136 | |||
| 137 | $form->addExtraClass('cms-edit-form fill-height'); |
||
| 138 | $form->setTemplate($this->getTemplatesWithSuffix('_EditForm')); |
||
| 139 | |||
| 140 | if ($form->Fields()->hasTabset()) { |
||
| 141 | $form->Fields()->findOrMakeTab('Root')->setTemplate('SilverStripe\\Forms\\CMSTabSet'); |
||
| 142 | $form->addExtraClass('center ss-tabset cms-tabset ' . $this->BaseCSSClasses()); |
||
| 143 | } |
||
| 144 | |||
| 145 | $this->extend('updateEditForm', $form); |
||
| 146 | |||
| 147 | return $form; |
||
| 148 | } |
||
| 150 |