Conditions | 19 |
Paths | 254 |
Total Lines | 105 |
Code Lines | 76 |
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 namespace EvolutionCMS\Legacy; |
||
235 | public function run($parent = 0) |
||
236 | { |
||
237 | global $_lang; |
||
238 | $modx = evolutionCMS(); |
||
239 | |||
240 | $tbl_site_content = $modx->getFullTableName('site_content'); |
||
241 | |||
242 | $ignore_ids = $this->ignore_ids; |
||
243 | $dirpath = $this->targetDir . '/'; |
||
244 | |||
245 | $prefix = $modx->config['friendly_url_prefix']; |
||
246 | $suffix = $modx->config['friendly_url_suffix']; |
||
247 | |||
248 | $tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>'; |
||
249 | $ph = array(); |
||
250 | |||
251 | $ph['status'] = 'fail'; |
||
252 | $ph['msg1'] = $_lang['export_site_failed']; |
||
253 | $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
||
254 | $msg_failed_no_write = $this->parsePlaceholder($tpl, $ph); |
||
255 | |||
256 | $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
||
257 | $msg_failed_no_retrieve = $this->parsePlaceholder($tpl, $ph); |
||
258 | |||
259 | $ph['status'] = 'success'; |
||
260 | $ph['msg1'] = $_lang['export_site_success']; |
||
261 | $ph['msg2'] = ''; |
||
262 | $msg_success = $this->parsePlaceholder($tpl, $ph); |
||
263 | |||
264 | $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
||
265 | $msg_success_skip_doc = $this->parsePlaceholder($tpl, $ph); |
||
266 | |||
267 | $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
||
268 | $msg_success_skip_dir = $this->parsePlaceholder($tpl, $ph); |
||
269 | |||
270 | $fields = "id, alias, pagetitle, isfolder, (content = '' AND template = 0) AS wasNull, published"; |
||
271 | $noncache = $_POST['includenoncache'] == 1 ? '' : 'AND cacheable=1'; |
||
272 | $where = "parent = '{$parent}' AND deleted=0 AND ((published=1 AND type='document') OR (isfolder=1)) {$noncache} {$ignore_ids}"; |
||
273 | $rs = $modx->getDatabase()->select($fields, $tbl_site_content, $where); |
||
274 | |||
275 | $ph = array(); |
||
276 | $ph['total'] = $this->total; |
||
277 | $folder_permission = octdec($modx->config['new_folder_permissions']); |
||
278 | while ($row = $modx->getDatabase()->getRow($rs)) { |
||
279 | $this->count++; |
||
280 | $filename = ''; |
||
281 | $row['count'] = $this->count; |
||
282 | $row['url'] = $modx->makeUrl($row['id']); |
||
283 | |||
284 | if (!$row['wasNull']) { // needs writing a document |
||
285 | $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix); |
||
286 | $filename = $dirpath . $docname; |
||
287 | if (!is_file($filename)) { |
||
288 | if ($row['published'] === '1') { |
||
289 | $status = $this->makeFile($row['id'], $filename); |
||
290 | switch ($status) { |
||
291 | case 'failed_no_write' : |
||
292 | $row['status'] = $msg_failed_no_write; |
||
293 | break; |
||
294 | case 'failed_no_retrieve': |
||
295 | $row['status'] = $msg_failed_no_retrieve; |
||
296 | break; |
||
297 | default: |
||
298 | $row['status'] = $msg_success; |
||
299 | } |
||
300 | } else { |
||
301 | $row['status'] = $msg_failed_no_retrieve; |
||
302 | } |
||
303 | } else { |
||
304 | $row['status'] = $msg_success_skip_doc; |
||
305 | } |
||
306 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
||
307 | } else { |
||
308 | $row['status'] = $msg_success_skip_dir; |
||
309 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
||
310 | } |
||
311 | if ($row['isfolder'] === '1' && ($modx->config['suffix_mode'] !== '1' || strpos($row['alias'], |
||
312 | '.') === false)) { // needs making a folder |
||
313 | $end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id']; |
||
314 | $dir_path = $dirpath . $end_dir; |
||
315 | if (strpos($dir_path, MODX_BASE_PATH) === false) { |
||
316 | return false; |
||
317 | } |
||
318 | if (!is_dir($dir_path)) { |
||
319 | if (is_file($dir_path)) { |
||
320 | @unlink($dir_path); |
||
321 | } |
||
322 | mkdir($dir_path); |
||
323 | @chmod($dir_path, $folder_permission); |
||
324 | |||
325 | } |
||
326 | |||
327 | |||
328 | if ($modx->config['make_folders'] === '1' && $row['published'] === '1') { |
||
329 | if (!empty($filename) && is_file($filename)) { |
||
330 | rename($filename, $dir_path . '/index.html'); |
||
331 | } |
||
332 | } |
||
333 | $this->targetDir = $dir_path; |
||
334 | $this->run($row['id']); |
||
335 | } |
||
336 | } |
||
337 | |||
338 | return implode("\n", $this->output); |
||
339 | } |
||
340 | |||
377 |
This check marks property names that have not been written in camelCase.
In camelCase names are written without any punctuation, the start of each new word being marked by a capital letter. Thus the name database connection string becomes
databaseConnectionString
.