| Conditions | 13 |
| Paths | 48 |
| Total Lines | 45 |
| Code Lines | 24 |
| 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 |
||
| 24 | public function copyDirectory($source, $destination, $file_count = 4000) |
||
| 25 | { |
||
| 26 | $destination = rtrim($destination, '\/\\'); |
||
| 27 | if (!is_dir($destination)) { |
||
| 28 | $created = mkdir($destination, 0700); |
||
| 29 | echo PHP_EOL . ' **** '. __LINE__ . 'Attempted to create: '. $destination. ($created ? 'Y' : 'N').' **** '. PHP_EOL; |
||
| 30 | } |
||
| 31 | |||
| 32 | /** @var \RecursiveDirectoryIterator $directoryIterator */ |
||
| 33 | $directoryIterator = new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS); |
||
| 34 | |||
| 35 | if (isset($this->output) && $this->output instanceof OutputInterface) { |
||
| 36 | $this->output->writeln('Now copying extracted files to '.$destination.' File count: '.$file_count); |
||
| 37 | $progress = new ProgressBar($this->output, $file_count); |
||
| 38 | $progress->start(); |
||
| 39 | |||
| 40 | $progress->setRedrawFrequency(10); |
||
| 41 | } |
||
| 42 | |||
| 43 | /** @var RecursiveIteratorIterator $recursiveIteratorIterator */ |
||
| 44 | $recursiveIteratorIterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST); |
||
| 45 | |||
| 46 | /** @var \DirectoryIterator $item */ |
||
| 47 | foreach ($recursiveIteratorIterator as $item) { |
||
| 48 | if ($item->isDir()) { |
||
| 49 | if (is_dir($destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName())) { |
||
| 50 | continue; |
||
| 51 | } |
||
| 52 | $created = mkdir($destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName()); |
||
| 53 | echo PHP_EOL . ' **** '. __LINE__ . 'Attempted to create: '. $destination. ($created ? 'Y' : 'N').' **** '. PHP_EOL; |
||
| 54 | |||
| 55 | } else { |
||
| 56 | copy($item, $destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName()); |
||
| 57 | } |
||
| 58 | |||
| 59 | if (isset($progress) && $progress instanceof ProgressBar) { |
||
| 60 | $progress->advance(); |
||
| 61 | } |
||
| 62 | |||
| 63 | } |
||
| 64 | |||
| 65 | if (isset($progress) && $progress instanceof ProgressBar) { |
||
| 66 | // ensures that the progress bar is at 100% |
||
| 67 | $progress->finish(); |
||
| 68 | $this->output->writeln(''); |
||
| 69 | } |
||
| 99 | } |