| Conditions | 53 |
| Paths | > 20000 |
| Total Lines | 206 |
| Code Lines | 133 |
| 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 |
||
| 320 | protected function _extractList($p_path, &$p_list_detail, $p_mode, |
||
| 321 | $p_file_list, $p_remove_path) |
||
| 322 | { |
||
| 323 | $v_result=true; |
||
| 324 | $v_nb = 0; |
||
| 325 | $v_extract_all = true; |
||
| 326 | $v_listing = false; |
||
| 327 | |||
| 328 | $p_path = $this->_translateWinPath($p_path, false); |
||
| 329 | if ($p_path == '' || (substr($p_path, 0, 1) != '/' |
||
| 330 | && substr($p_path, 0, 3) != "../" && !strpos($p_path, ':'))) { |
||
| 331 | $p_path = "./".$p_path; |
||
| 332 | } |
||
| 333 | $p_remove_path = $this->_translateWinPath($p_remove_path); |
||
| 334 | |||
| 335 | // ----- Look for path to remove format (should end by /) |
||
| 336 | if (($p_remove_path != '') && (substr($p_remove_path, -1) != '/')) |
||
| 337 | $p_remove_path .= '/'; |
||
| 338 | $p_remove_path_size = strlen($p_remove_path); |
||
| 339 | |||
| 340 | switch ($p_mode) { |
||
| 341 | case "complete" : |
||
| 342 | $v_extract_all = true; |
||
| 343 | $v_listing = false; |
||
| 344 | break; |
||
| 345 | case "partial" : |
||
| 346 | $v_extract_all = false; |
||
| 347 | $v_listing = false; |
||
| 348 | break; |
||
| 349 | case "list" : |
||
| 350 | $v_extract_all = false; |
||
| 351 | $v_listing = true; |
||
| 352 | break; |
||
| 353 | default : |
||
| 354 | $this->_error('Invalid extract mode ('.$p_mode.')'); |
||
| 355 | return false; |
||
| 356 | } |
||
| 357 | |||
| 358 | clearstatcache(); |
||
| 359 | |||
| 360 | while (strlen($v_binary_data = $this->_readBlock()) != 0) |
||
| 361 | { |
||
| 362 | $v_extract_file = false; |
||
| 363 | $v_extraction_stopped = 0; |
||
| 364 | |||
| 365 | if (!$this->_readHeader($v_binary_data, $v_header)) |
||
| 366 | return false; |
||
| 367 | |||
| 368 | if ($v_header['filename'] == '') { |
||
| 369 | continue; |
||
| 370 | } |
||
| 371 | |||
| 372 | // ----- Look for long filename |
||
| 373 | if ($v_header['typeflag'] == 'L') { |
||
| 374 | if (!$this->_readLongHeader($v_header)) |
||
| 375 | return false; |
||
| 376 | } |
||
| 377 | |||
| 378 | if ((!$v_extract_all) && (is_array($p_file_list))) { |
||
| 379 | // ----- By default no unzip if the file is not found |
||
| 380 | $v_extract_file = false; |
||
| 381 | |||
| 382 | for ($i=0; $i<sizeof($p_file_list); $i++) { |
||
| 383 | // ----- Look if it is a directory |
||
| 384 | if (substr($p_file_list[$i], -1) == '/') { |
||
| 385 | // ----- Look if the directory is in the filename path |
||
| 386 | if ((strlen($v_header['filename']) > strlen($p_file_list[$i])) |
||
| 387 | && (substr($v_header['filename'], 0, strlen($p_file_list[$i])) |
||
| 388 | == $p_file_list[$i])) { |
||
| 389 | $v_extract_file = true; |
||
| 390 | break; |
||
| 391 | } |
||
| 392 | } |
||
| 393 | |||
| 394 | // ----- It is a file, so compare the file names |
||
| 395 | elseif ($p_file_list[$i] == $v_header['filename']) { |
||
| 396 | $v_extract_file = true; |
||
| 397 | break; |
||
| 398 | } |
||
| 399 | } |
||
| 400 | } else { |
||
| 401 | $v_extract_file = true; |
||
| 402 | } |
||
| 403 | |||
| 404 | // ----- Look if this file need to be extracted |
||
| 405 | if (($v_extract_file) && (!$v_listing)) |
||
| 406 | { |
||
| 407 | if (($p_remove_path != '') |
||
| 408 | && (substr($v_header['filename'], 0, $p_remove_path_size) |
||
| 409 | == $p_remove_path)) |
||
| 410 | $v_header['filename'] = substr($v_header['filename'], |
||
| 411 | $p_remove_path_size); |
||
| 412 | if (($p_path != './') && ($p_path != '/')) { |
||
| 413 | while (substr($p_path, -1) == '/') |
||
| 414 | $p_path = substr($p_path, 0, strlen($p_path)-1); |
||
| 415 | |||
| 416 | if (substr($v_header['filename'], 0, 1) == '/') |
||
| 417 | $v_header['filename'] = $p_path.$v_header['filename']; |
||
| 418 | else |
||
| 419 | $v_header['filename'] = $p_path.'/'.$v_header['filename']; |
||
| 420 | } |
||
| 421 | if (file_exists($v_header['filename'])) { |
||
| 422 | if ( (@is_dir($v_header['filename'])) |
||
| 423 | && ($v_header['typeflag'] == '')) { |
||
| 424 | $this->_error('File '.$v_header['filename'] |
||
| 425 | .' already exists as a directory'); |
||
| 426 | return false; |
||
| 427 | } |
||
| 428 | if ( ($this->_isArchive($v_header['filename'])) |
||
| 429 | && ($v_header['typeflag'] == "5")) { |
||
| 430 | $this->_error('Directory '.$v_header['filename'] |
||
| 431 | .' already exists as a file'); |
||
| 432 | return false; |
||
| 433 | } |
||
| 434 | if (!is_writeable($v_header['filename'])) { |
||
| 435 | $this->_error('File '.$v_header['filename'] |
||
| 436 | .' already exists and is write protected'); |
||
| 437 | return false; |
||
| 438 | } |
||
| 439 | if (filemtime($v_header['filename']) > $v_header['mtime']) { |
||
| 440 | // To be completed : An error or silent no replace ? |
||
| 441 | } |
||
| 442 | } |
||
| 443 | |||
| 444 | // ----- Check the directory availability and create it if necessary |
||
| 445 | elseif (($v_result |
||
| 446 | = $this->_dirCheck(($v_header['typeflag'] == "5" |
||
| 447 | ?$v_header['filename'] |
||
| 448 | :dirname($v_header['filename'])))) != 1) { |
||
| 449 | $this->_error('Unable to create path for '.$v_header['filename']); |
||
| 450 | return false; |
||
| 451 | } |
||
| 452 | |||
| 453 | if ($v_extract_file) { |
||
| 454 | if ($v_header['typeflag'] == "5") { |
||
| 455 | if (!@file_exists($v_header['filename'])) { |
||
| 456 | if (!@mkdir($v_header['filename'], PRADO_CHMOD)) { |
||
| 457 | $this->_error('Unable to create directory {' |
||
| 458 | .$v_header['filename'].'}'); |
||
| 459 | return false; |
||
| 460 | } |
||
| 461 | chmod($v_header['filename'], PRADO_CHMOD); |
||
| 462 | } |
||
| 463 | } else { |
||
| 464 | if (($v_dest_file = @fopen($v_header['filename'], "wb")) == 0) { |
||
| 465 | $this->_error('Error while opening {'.$v_header['filename'] |
||
| 466 | .'} in write binary mode'); |
||
| 467 | return false; |
||
| 468 | } else { |
||
| 469 | $n = floor($v_header['size']/512); |
||
| 470 | for ($i=0; $i<$n; $i++) { |
||
| 471 | $v_content = $this->_readBlock(); |
||
| 472 | fwrite($v_dest_file, $v_content, 512); |
||
| 473 | } |
||
| 474 | if (($v_header['size'] % 512) != 0) { |
||
| 475 | $v_content = $this->_readBlock(); |
||
| 476 | fwrite($v_dest_file, $v_content, ($v_header['size'] % 512)); |
||
| 477 | } |
||
| 478 | |||
| 479 | @fclose($v_dest_file); |
||
| 480 | |||
| 481 | // ----- Change the file mode, mtime |
||
| 482 | @touch($v_header['filename'], $v_header['mtime']); |
||
| 483 | // To be completed |
||
| 484 | //chmod($v_header[filename], DecOct($v_header[mode])); |
||
| 485 | } |
||
| 486 | |||
| 487 | // ----- Check the file size |
||
| 488 | clearstatcache(); |
||
| 489 | if (filesize($v_header['filename']) != $v_header['size']) { |
||
| 490 | $this->_error('Extracted file '.$v_header['filename'] |
||
| 491 | .' does not have the correct file size \'' |
||
| 492 | .filesize($v_header['filename']) |
||
| 493 | .'\' ('.$v_header['size'] |
||
| 494 | .' expected). Archive may be corrupted.'); |
||
| 495 | return false; |
||
| 496 | } |
||
| 497 | } |
||
| 498 | } else { |
||
| 499 | $this->_jumpBlock(ceil(($v_header['size']/512))); |
||
| 500 | } |
||
| 501 | } else { |
||
| 502 | $this->_jumpBlock(ceil(($v_header['size']/512))); |
||
| 503 | } |
||
| 504 | |||
| 505 | /* TBC : Seems to be unused ... |
||
| 506 | if ($this->_compress) |
||
| 507 | $v_end_of_file = @gzeof($this->_file); |
||
| 508 | else |
||
| 509 | $v_end_of_file = @feof($this->_file); |
||
| 510 | */ |
||
| 511 | |||
| 512 | if ($v_listing || $v_extract_file || $v_extraction_stopped) { |
||
| 513 | // ----- Log extracted files |
||
| 514 | if (($v_file_dir = dirname($v_header['filename'])) |
||
| 515 | == $v_header['filename']) |
||
| 516 | $v_file_dir = ''; |
||
| 517 | if ((substr($v_header['filename'], 0, 1) == '/') && ($v_file_dir == '')) |
||
| 518 | $v_file_dir = '/'; |
||
| 519 | |||
| 520 | $p_list_detail[$v_nb++] = $v_header; |
||
| 521 | } |
||
| 522 | } |
||
| 523 | |||
| 524 | return true; |
||
| 525 | } |
||
| 526 | |||
| 572 |
This check marks parameter 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.