| Conditions | 11 |
| Paths | 48 |
| Total Lines | 43 |
| Code Lines | 22 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| 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 |
||
| 45 | public function copyDirectory($source, $destination, $file_count = 4000) |
||
| 46 | { |
||
| 47 | $destination = rtrim($destination, '\/\\'); |
||
| 48 | if (!is_dir($destination)) { |
||
| 49 | $this->makeDirectory($destination); |
||
| 50 | } |
||
| 51 | |||
| 52 | /** @var \RecursiveDirectoryIterator $directoryIterator */ |
||
| 53 | $directoryIterator = new RecursiveDirectoryIterator($source, FilesystemIterator::SKIP_DOTS); |
||
| 54 | |||
| 55 | if (isset($this->output) && $this->output instanceof OutputInterface) { |
||
| 56 | $this->output->writeln('Now copying extracted files to '.$destination.' File count: '.$file_count); |
||
| 57 | $progress = new ProgressBar($this->output, $file_count); |
||
| 58 | $progress->start(); |
||
| 59 | |||
| 60 | $progress->setRedrawFrequency(10); |
||
| 61 | } |
||
| 62 | |||
| 63 | /** @var RecursiveIteratorIterator $recursiveIteratorIterator */ |
||
| 64 | $recursiveIteratorIterator = new RecursiveIteratorIterator($directoryIterator, RecursiveIteratorIterator::SELF_FIRST); |
||
| 65 | |||
| 66 | /** @var \DirectoryIterator $item */ |
||
| 67 | foreach ($recursiveIteratorIterator as $item) { |
||
| 68 | if ($item->isDir()) { |
||
| 69 | if (is_dir($destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName())) { |
||
| 70 | continue; |
||
| 71 | } |
||
| 72 | $this->makeDirectory($destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName()); |
||
| 73 | |||
| 74 | } else { |
||
| 75 | copy($item, $destination.DIRECTORY_SEPARATOR.$recursiveIteratorIterator->getSubPathName()); |
||
| 76 | } |
||
| 77 | |||
| 78 | if (isset($progress) && $progress instanceof ProgressBar) { |
||
| 79 | $progress->advance(); |
||
| 80 | } |
||
| 81 | |||
| 82 | } |
||
| 83 | |||
| 84 | if (isset($progress) && $progress instanceof ProgressBar) { |
||
| 85 | // ensures that the progress bar is at 100% |
||
| 86 | $progress->finish(); |
||
| 87 | $this->output->writeln(''); |
||
| 88 | } |
||
| 132 | } |