| Conditions | 15 |
| Paths | 36 |
| Total Lines | 48 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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:
Methods with many parameters are not only hard to understand, but their parameters also often become inconsistent when you need more, or different data.
There are several approaches to avoid long parameter lists:
| 1 | <?php declare(strict_types=1); |
||
| 111 | protected function scanUser( |
||
| 112 | string $user, OutputInterface $output, bool $rescan, bool $skipDirty, bool $skipArt, |
||
| 113 | bool $cleanObsolete, ?string $folder, bool $debug) : void { |
||
| 114 | |||
| 115 | $output->writeln("Check library scan status for <info>$user</info>" . ($folder ? " in path '$folder'..." : '...')); |
||
| 116 | $startTime = \hrtime(true); |
||
| 117 | \extract($this->scanner->getStatusOfLibraryFiles($user, $folder)); // populate $unscannedFiles, $obsoleteFiles, $dirtyFiles, $scannedCount |
||
| 118 | $statusTime = (int)((\hrtime(true) - $startTime) / 1000000); |
||
| 119 | $unscannedCount = \count($unscannedFiles); |
||
| 120 | $dirtyCount = \count($dirtyFiles); |
||
| 121 | $obsoleteCount = \count($obsoleteFiles); |
||
| 122 | |||
| 123 | $output->writeln(" Status got in $statusTime ms"); |
||
| 124 | $output->writeln(" Scanned files: $scannedCount"); |
||
| 125 | $output->writeln(" Unscanned files: $unscannedCount"); |
||
| 126 | $output->writeln(" Dirty files: $dirtyCount" . (($dirtyCount && $skipDirty) ? ' (skipped)' : '')); |
||
| 127 | $output->writeln(" Obsolete files: $obsoleteCount" . (($obsoleteCount && !$cleanObsolete) ? ' (use --clean-obsolete to remove)' : '')); |
||
| 128 | $output->writeln(""); |
||
| 129 | |||
| 130 | if ($cleanObsolete && !empty($obsoleteFiles)) { |
||
| 131 | if ($this->scanner->deleteAudio($obsoleteFiles, [$user])) { |
||
| 132 | $output->writeln("The obsolete files no longer available in the the library of <info>$user</info> were removed"); |
||
| 133 | } else { |
||
| 134 | $output->writeln("<error>Failed</error> to remove any obsolete files of <info>$user</info>!"); |
||
| 135 | } |
||
| 136 | } |
||
| 137 | |||
| 138 | if ($rescan) { |
||
| 139 | $filesToScan = $this->scanner->getAllMusicFileIds($user, $folder); |
||
| 140 | } else { |
||
| 141 | $filesToScan = $unscannedFiles; |
||
| 142 | if (!$skipDirty) { |
||
| 143 | $filesToScan = \array_merge($filesToScan, $dirtyFiles); |
||
| 144 | } |
||
| 145 | } |
||
| 146 | $output->writeln('Total ' . \count($filesToScan) . ' files to scan' . ($folder ? " in '$folder'" : '')); |
||
| 147 | |||
| 148 | if (\count($filesToScan)) { |
||
| 149 | $stats = $this->scanner->scanFiles($user, $filesToScan, $debug ? $output : null); |
||
| 150 | $output->writeln("Added or updated {$stats['count']} files in database of <info>$user</info>"); |
||
| 151 | $output->writeln(' Time consumed to analyze files: ' . ($stats['anlz_time'] / 1000) . ' s'); |
||
| 152 | $output->writeln(' Time consumed to update DB: ' . ($stats['db_time'] / 1000) . ' s'); |
||
| 153 | } |
||
| 154 | |||
| 155 | if ($skipArt) { |
||
| 156 | $output->writeln("Cover art search skipped"); |
||
| 157 | } else { |
||
| 158 | $this->searchArt($user, $output); |
||
| 159 | } |
||
| 181 |