| Conditions | 18 |
| Paths | 127 |
| Total Lines | 103 |
| 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; |
||
| 259 | public function run($parent = 0) |
||
| 260 | { |
||
| 261 | global $_lang; |
||
| 262 | $modx = evolutionCMS(); |
||
| 263 | |||
| 264 | $ignore_ids = $this->ignore_ids; |
||
| 265 | $dirpath = $this->targetDir . '/'; |
||
| 266 | |||
| 267 | $prefix = $modx->getConfig('friendly_url_prefix'); |
||
| 268 | $suffix = $modx->getConfig('friendly_url_suffix'); |
||
| 269 | |||
| 270 | $tpl = ' <span class="[+status+]">[+msg1+]</span> [+msg2+]</span>'; |
||
| 271 | $ph = array(); |
||
| 272 | |||
| 273 | $ph['status'] = 'fail'; |
||
| 274 | $ph['msg1'] = $_lang['export_site_failed']; |
||
| 275 | $ph['msg2'] = $_lang["export_site_failed_no_write"] . ' - ' . $dirpath; |
||
| 276 | $msg_failed_no_write = $this->parsePlaceholder($tpl, $ph); |
||
| 277 | |||
| 278 | $ph['msg2'] = $_lang["export_site_failed_no_retrieve"]; |
||
| 279 | $msg_failed_no_retrieve = $this->parsePlaceholder($tpl, $ph); |
||
| 280 | |||
| 281 | $ph['status'] = 'success'; |
||
| 282 | $ph['msg1'] = $_lang['export_site_success']; |
||
| 283 | $ph['msg2'] = ''; |
||
| 284 | $msg_success = $this->parsePlaceholder($tpl, $ph); |
||
| 285 | |||
| 286 | $ph['msg2'] = $_lang['export_site_success_skip_doc']; |
||
| 287 | $msg_success_skip_doc = $this->parsePlaceholder($tpl, $ph); |
||
| 288 | |||
| 289 | $ph['msg2'] = $_lang['export_site_success_skip_dir']; |
||
| 290 | $msg_success_skip_dir = $this->parsePlaceholder($tpl, $ph); |
||
| 291 | |||
| 292 | $data = $this->makeQuery($ignore_ids, (bool)get_by_key($_POST, 'includenoncache', false)) |
||
| 293 | ->where('parent', '=', $parent) |
||
| 294 | ->get(); |
||
| 295 | |||
| 296 | $ph = array(); |
||
| 297 | $ph['total'] = $this->total; |
||
| 298 | $folder_permission = octdec($modx->getConfig('new_folder_permissions')); |
||
| 299 | /** @var Models\SiteContent $item */ |
||
| 300 | foreach ($data as $item) { |
||
| 301 | $this->count++; |
||
| 302 | $row = $item->toArray(); |
||
| 303 | $row['count'] = $this->count; |
||
| 304 | $row['url'] = UrlProcessor::makeUrl($row['id']); |
||
| 305 | $filename = ''; |
||
| 306 | |||
| 307 | if ($item->wasNull === false) { // needs writing a document |
||
| 308 | $docname = $this->getFileName($row['id'], $row['alias'], $prefix, $suffix); |
||
| 309 | $filename = $dirpath . $docname; |
||
| 310 | if (!is_file($filename)) { |
||
| 311 | if ($row['published'] === 1) { |
||
| 312 | $status = $this->makeFile($row['id'], $filename); |
||
| 313 | switch ($status) { |
||
| 314 | case 'failed_no_write' : |
||
| 315 | $row['status'] = $msg_failed_no_write; |
||
| 316 | break; |
||
| 317 | case 'failed_no_retrieve': |
||
| 318 | $row['status'] = $msg_failed_no_retrieve; |
||
| 319 | break; |
||
| 320 | default: |
||
| 321 | $row['status'] = $msg_success; |
||
| 322 | } |
||
| 323 | } else { |
||
| 324 | $row['status'] = $msg_failed_no_retrieve; |
||
| 325 | } |
||
| 326 | } else { |
||
| 327 | $row['status'] = $msg_success_skip_doc; |
||
| 328 | } |
||
| 329 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
||
| 330 | } else { |
||
| 331 | $row['status'] = $msg_success_skip_dir; |
||
| 332 | $this->output[] = $this->parsePlaceholder($_lang['export_site_exporting_document'], $row); |
||
| 333 | } |
||
| 334 | if ($row['isfolder'] === '1' && ($modx->getConfig('suffix_mode') != '1' || strpos($row['alias'], |
||
| 335 | '.') === false)) { // needs making a folder |
||
| 336 | $end_dir = ($row['alias'] !== '') ? $row['alias'] : $row['id']; |
||
| 337 | $dir_path = $dirpath . $end_dir; |
||
| 338 | if (strpos($dir_path, MODX_BASE_PATH) === false) { |
||
| 339 | return false; |
||
| 340 | } |
||
| 341 | if (!is_dir($dir_path)) { |
||
| 342 | if (is_file($dir_path)) { |
||
| 343 | @unlink($dir_path); |
||
| 344 | } |
||
| 345 | mkdir($dir_path); |
||
| 346 | @chmod($dir_path, $folder_permission); |
||
| 347 | |||
| 348 | } |
||
| 349 | |||
| 350 | if ($modx->getConfig('make_folders') == '1' && $row['published'] === '1') { |
||
| 351 | if (!empty($filename) && is_file($filename)) { |
||
| 352 | rename($filename, $dir_path . '/index.html'); |
||
| 353 | } |
||
| 354 | } |
||
| 355 | $this->targetDir = $dir_path; |
||
| 356 | $this->run($row['id']); |
||
| 357 | } |
||
| 358 | } |
||
| 359 | |||
| 360 | return implode("\n", $this->output); |
||
| 361 | } |
||
| 362 | |||
| 399 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.