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