Conditions | 9 |
Paths | 8 |
Total Lines | 105 |
Code Lines | 75 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
71 | public function Form() { |
||
72 | $fields = new FieldList(); |
||
73 | $source = array(); |
||
74 | |||
75 | $fields->push(new HeaderField( |
||
76 | 'Header', |
||
77 | _t('RemoveOrphanedPagesTask.HEADER', 'Remove all orphaned pages task') |
||
78 | )); |
||
79 | $fields->push(new LiteralField( |
||
80 | 'Description', |
||
81 | $this->description |
||
82 | )); |
||
83 | |||
84 | $orphans = $this->getOrphanedPages($this->orphanedSearchClass); |
||
85 | if($orphans) foreach($orphans as $orphan) { |
||
86 | $latestVersion = Versioned::get_latest_version($this->orphanedSearchClass, $orphan->ID); |
||
87 | $latestAuthor = DataObject::get_by_id('Member', $latestVersion->AuthorID); |
||
88 | $orphanBaseClass = ClassInfo::baseDataClass($this->orphanedSearchClass); |
||
89 | $stageRecord = Versioned::get_one_by_stage( |
||
|
|||
90 | $this->orphanedSearchClass, |
||
91 | 'Stage', |
||
92 | array("\"$orphanBaseClass\".\"ID\"" => $orphan->ID) |
||
93 | ); |
||
94 | $liveRecord = Versioned::get_one_by_stage( |
||
95 | $this->orphanedSearchClass, |
||
96 | 'Live', |
||
97 | array("\"$orphanBaseClass\".\"ID\"" => $orphan->ID) |
||
98 | ); |
||
99 | $label = sprintf( |
||
100 | '<a href="admin/pages/edit/show/%d">%s</a> <small>(#%d, Last Modified Date: %s, Last Modifier: %s, %s)</small>', |
||
101 | $orphan->ID, |
||
102 | $orphan->Title, |
||
103 | $orphan->ID, |
||
104 | Date::create($orphan->LastEdited)->Nice(), |
||
105 | ($latestAuthor) ? $latestAuthor->Title : 'unknown', |
||
106 | ($liveRecord) ? 'is published' : 'not published' |
||
107 | ); |
||
108 | $source[$orphan->ID] = $label; |
||
109 | } |
||
110 | |||
111 | if($orphans && $orphans->Count()) { |
||
112 | $fields->push(new CheckboxSetField('OrphanIDs', false, $source)); |
||
113 | $fields->push(new LiteralField( |
||
114 | 'SelectAllLiteral', |
||
115 | sprintf( |
||
116 | '<p><a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'checked\'); return false;">%s</a> ', |
||
117 | _t('RemoveOrphanedPagesTask.SELECTALL', 'select all') |
||
118 | ) |
||
119 | )); |
||
120 | $fields->push(new LiteralField( |
||
121 | 'UnselectAllLiteral', |
||
122 | sprintf( |
||
123 | '<a href="#" onclick="javascript:jQuery(\'#Form_Form_OrphanIDs :checkbox\').attr(\'checked\', \'\'); return false;">%s</a></p>', |
||
124 | _t('RemoveOrphanedPagesTask.UNSELECTALL', 'unselect all') |
||
125 | ) |
||
126 | )); |
||
127 | $fields->push(new OptionSetField( |
||
128 | 'OrphanOperation', |
||
129 | _t('RemoveOrphanedPagesTask.CHOOSEOPERATION', 'Choose operation:'), |
||
130 | array( |
||
131 | 'rebase' => _t( |
||
132 | 'RemoveOrphanedPagesTask.OPERATION_REBASE', |
||
133 | sprintf( |
||
134 | 'Rebase selected to a new holder page "%s" and unpublish. None of these pages will show up for website visitors.', |
||
135 | $this->rebaseHolderTitle() |
||
136 | ) |
||
137 | ), |
||
138 | 'remove' => _t('RemoveOrphanedPagesTask.OPERATION_REMOVE', 'Remove selected from all stages (WARNING: Will destroy all selected pages from both stage and live)'), |
||
139 | ), |
||
140 | 'rebase' |
||
141 | )); |
||
142 | $fields->push(new LiteralField( |
||
143 | 'Warning', |
||
144 | sprintf('<p class="message">%s</p>', |
||
145 | _t( |
||
146 | 'RemoveOrphanedPagesTask.DELETEWARNING', |
||
147 | 'Warning: These operations are not reversible. Please handle with care.' |
||
148 | ) |
||
149 | ) |
||
150 | )); |
||
151 | } else { |
||
152 | $fields->push(new LiteralField( |
||
153 | 'NotFoundLabel', |
||
154 | sprintf( |
||
155 | '<p class="message">%s</p>', |
||
156 | _t('RemoveOrphanedPagesTask.NONEFOUND', 'No orphans found') |
||
157 | ) |
||
158 | )); |
||
159 | } |
||
160 | |||
161 | $form = new Form( |
||
162 | $this, |
||
163 | 'Form', |
||
164 | $fields, |
||
165 | new FieldList( |
||
166 | new FormAction('doSubmit', _t('RemoveOrphanedPagesTask.BUTTONRUN', 'Run')) |
||
167 | ) |
||
168 | ); |
||
169 | |||
170 | if(!$orphans || !$orphans->Count()) { |
||
171 | $form->makeReadonly(); |
||
172 | } |
||
173 | |||
174 | return $form; |
||
175 | } |
||
176 | |||
340 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.