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