Conditions | 25 |
Paths | 6208 |
Total Lines | 150 |
Code Lines | 116 |
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 |
||
111 | private function main() { |
||
112 | global $WT_TREE; |
||
113 | |||
114 | $this->plugins = $this->getPluginList(); // List of available plugins |
||
115 | $this->plugin = Filter::get('plugin'); // User parameters |
||
116 | $this->xref = Filter::get('xref', WT_REGEX_XREF); |
||
117 | $this->action = Filter::get('action'); |
||
118 | $this->data = Filter::get('data'); |
||
119 | |||
120 | // Don't do any processing until a plugin is chosen. |
||
121 | if ($this->plugin && array_key_exists($this->plugin, $this->plugins)) { |
||
122 | $this->PLUGIN = new $this->plugin; |
||
123 | $this->PLUGIN->getOptions(); |
||
124 | $this->getAllXrefs(); |
||
125 | |||
126 | switch ($this->action) { |
||
127 | case 'update': |
||
128 | $record = self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]); |
||
129 | if ($this->PLUGIN->doesRecordNeedUpdate($this->xref, $record)) { |
||
130 | $newrecord = $this->PLUGIN->updateRecord($this->xref, $record); |
||
131 | if ($newrecord != $record) { |
||
132 | if ($newrecord) { |
||
133 | GedcomRecord::getInstance($this->xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
||
134 | } else { |
||
135 | GedcomRecord::getInstance($this->xref, $WT_TREE)->deleteRecord(); |
||
136 | } |
||
137 | } |
||
138 | } |
||
139 | $this->xref = $this->findNextXref($this->xref); |
||
140 | break; |
||
141 | case 'update_all': |
||
142 | foreach ($this->all_xrefs as $xref => $type) { |
||
143 | $record = self::getLatestRecord($xref, $type); |
||
144 | if ($this->PLUGIN->doesRecordNeedUpdate($xref, $record)) { |
||
145 | $newrecord = $this->PLUGIN->updateRecord($xref, $record); |
||
146 | if ($newrecord != $record) { |
||
147 | if ($newrecord) { |
||
148 | GedcomRecord::getInstance($xref, $WT_TREE)->updateRecord($newrecord, !$this->PLUGIN->chan); |
||
149 | } else { |
||
150 | GedcomRecord::getInstance($xref, $WT_TREE)->deleteRecord(); |
||
151 | } |
||
152 | } |
||
153 | } |
||
154 | } |
||
155 | $this->xref = ''; |
||
156 | break; |
||
157 | } |
||
158 | |||
159 | // Make sure that our requested record really does need updating. |
||
160 | // It may have been updated in another session, or may not have |
||
161 | // been specified at all. |
||
162 | if (array_key_exists($this->xref, $this->all_xrefs) && |
||
163 | $this->PLUGIN->doesRecordNeedUpdate($this->xref, self::getLatestRecord($this->xref, $this->all_xrefs[$this->xref]))) { |
||
164 | $this->curr_xref = $this->xref; |
||
165 | } |
||
166 | // The requested record doesn't need updating - find one that does |
||
167 | if (!$this->curr_xref) { |
||
168 | $this->curr_xref = $this->findNextXref($this->xref); |
||
169 | } |
||
170 | if (!$this->curr_xref) { |
||
171 | $this->curr_xref = $this->findPrevXref($this->xref); |
||
172 | } |
||
173 | // If we've found a record to update, get details and look for the next/prev |
||
174 | if ($this->curr_xref) { |
||
175 | $this->prev_xref = $this->findPrevXref($this->curr_xref); |
||
176 | $this->next_xref = $this->findNextXref($this->curr_xref); |
||
177 | } |
||
178 | } |
||
179 | |||
180 | // HTML common to all pages |
||
181 | $controller = new PageController; |
||
182 | $controller |
||
183 | ->setPageTitle(I18N::translate('Batch update')) |
||
184 | ->restrictAccess(Auth::isAdmin()) |
||
185 | ->pageHeader(); |
||
186 | |||
187 | echo $this->getJavascript(); |
||
188 | echo Bootstrap4::breadcrumbs([ |
||
189 | route('admin-control-panel') => I18N::translate('Control panel'), |
||
190 | route('admin-modules') => I18N::translate('Module administration'), |
||
191 | ], $controller->getPageTitle()); |
||
192 | ?> |
||
193 | <h1><?= $controller->getPageTitle() ?></h1> |
||
194 | |||
195 | <form id="batch_update_form" class="form-horizontal" action="module.php"> |
||
196 | <input type="hidden" name="mod" value="batch_update"> |
||
197 | <input type="hidden" name="mod_action" value="admin_batch_update"> |
||
198 | <input type="hidden" name="xref" value="' . $this->xref . '"> |
||
199 | <input type="hidden" name="action" value=""><?php // will be set by javascript for next update ?> |
||
200 | <input type="hidden" name="data" value=""><?php // will be set by javascript for next update ?> |
||
201 | <div class="row form-group"> |
||
202 | <label class="col-sm-3 col-form-label"><?= I18N::translate('Family tree') ?></label> |
||
203 | <div class="col-sm-9"> |
||
204 | <?= Bootstrap4::select(Tree::getNameList(), $WT_TREE->getName(), ['id' => 'ged', 'name' => 'ged', 'onchange' => 'reset_reload();']) ?> |
||
205 | </div> |
||
206 | </div> |
||
207 | <div class="row form-group"> |
||
208 | <label class="col-sm-3 col-form-label"><?= I18N::translate('Batch update') ?></label> |
||
209 | <div class="col-sm-9"> |
||
210 | <select class="form-control" name="plugin" onchange="reset_reload();"> |
||
211 | <?php if (!$this->plugin): ?> |
||
212 | <option value="" selected></option> |
||
213 | <?php endif ?> |
||
214 | <?php foreach ($this->plugins as $class => $plugin): ?> |
||
215 | <option value="<?= $class ?>" <?= $this->plugin == $class ? 'selected' : '' ?>><?= $plugin->getName() ?></option> |
||
216 | <?php endforeach ?> |
||
217 | </select> |
||
218 | <?php if ($this->PLUGIN): ?> |
||
219 | <p class="small text-muted"><?= $this->PLUGIN->getDescription() ?></p> |
||
220 | <?php endif ?> |
||
221 | </div> |
||
222 | </div> |
||
223 | |||
224 | <?php if (!Auth::user()->getPreference('auto_accept')): ?> |
||
225 | <div class="alert alert-danger"> |
||
226 | <?= I18N::translate('Your user account does not have “automatically accept changes” enabled. You will only be able to change one record at a time.') ?> |
||
227 | </div> |
||
228 | <?php endif ?> |
||
229 | |||
230 | <?php // If a plugin is selected, display the details ?> |
||
231 | <?php if ($this->PLUGIN): ?> |
||
232 | <?= $this->PLUGIN->getOptionsForm() ?> |
||
233 | <?php if (substr($this->action, -4) == '_all'): ?> |
||
234 | <?php // Reset - otherwise we might "undo all changes", which refreshes the ?> |
||
235 | <?php // page, which makes them all again! ?> |
||
236 | <script>reset_reload();</script> |
||
237 | <?php else: ?> |
||
238 | <hr> |
||
239 | <div id="batch_update2" class="col-sm-12"> |
||
240 | <?php if ($this->curr_xref): ?> |
||
241 | <?php // Create an object, so we can get the latest version of the name. ?> |
||
242 | <?php $this->record = GedcomRecord::getInstance($this->curr_xref, $WT_TREE) ?> |
||
243 | <div class="row form-group"> |
||
244 | <?= self::createSubmitButton(I18N::translate('previous'), $this->prev_xref) ?> |
||
245 | <?= self::createSubmitButton(I18N::translate('next'), $this->next_xref) ?> |
||
246 | </div> |
||
247 | <div class="row form-group"> |
||
248 | <a class="lead" href="<?= e($this->record->url()) ?>"><?= $this->record->getFullName() ?></a> |
||
249 | <?= $this->PLUGIN->getActionPreview($this->record) ?> |
||
250 | </div> |
||
251 | <div class="row form-group"> |
||
252 | <?= implode(' ', $this->PLUGIN->getActionButtons($this->curr_xref)) ?> |
||
253 | </div> |
||
254 | <?php else: ?> |
||
255 | <div class="alert alert-info"><?= I18N::translate('Nothing found.') ?></div> |
||
256 | <?php endif ?> |
||
257 | </div> |
||
258 | <?php endif ?> |
||
259 | <?php endif ?> |
||
260 | </form> |
||
261 | <?php |
||
441 |
This check looks for function or method calls that always return null and whose return value is used.
The method
getObject()
can return nothing but null, so it makes no sense to use the return value.The reason is most likely that a function or method is imcomplete or has been reduced for debug purposes.