| Conditions | 8 |
| Paths | 6 |
| Total Lines | 66 |
| Code Lines | 38 |
| 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 declare(strict_types=1); |
||
| 127 | private function shouldRemoveFolders(FilesystemObjects $foldersToRemove, Path $downloadPath): bool |
||
| 128 | { |
||
| 129 | $this->ui->write( |
||
| 130 | sprintf( |
||
| 131 | 'Synchronize the <info>%s</info> folder with the downloaded contents... ', |
||
| 132 | (string) $downloadPath |
||
| 133 | ) |
||
| 134 | ); |
||
| 135 | |||
| 136 | if ($foldersToRemove->isEmpty()) { |
||
| 137 | $this->ui->writeln('<info>Done.</info>'); |
||
| 138 | |||
| 139 | return false; |
||
| 140 | } |
||
| 141 | |||
| 142 | $this->ui->writeln(PHP_EOL); |
||
| 143 | |||
| 144 | if (!$this->ui->isDryRun() && !$this->ui->isInteractive()) { |
||
| 145 | return true; |
||
| 146 | } |
||
| 147 | |||
| 148 | $confirmationDefault = true; |
||
| 149 | |||
| 150 | // If there's less than 10 folders, we can display them |
||
| 151 | $nbFoldersToRemove = $foldersToRemove->count(); |
||
| 152 | if ($nbFoldersToRemove <= 10) { |
||
| 153 | $this->ui->writeln( |
||
| 154 | sprintf( |
||
| 155 | '%sThe script is about to remove the following folders from <info>%s</info>:', |
||
| 156 | $this->ui->indent(), |
||
| 157 | (string) $downloadPath |
||
| 158 | ) |
||
| 159 | ); |
||
| 160 | $this->ui->listing( |
||
| 161 | $foldersToRemove |
||
| 162 | ->map(function (\SplFileInfo $folder) use ($downloadPath) { |
||
| 163 | return sprintf( |
||
| 164 | '<info>%s</info>', |
||
| 165 | str_replace((string) $downloadPath.DIRECTORY_SEPARATOR, '', $folder->getRealPath()) |
||
| 166 | ); |
||
| 167 | }) |
||
| 168 | ->toArray(), |
||
| 169 | 3 |
||
| 170 | ); |
||
| 171 | } else { |
||
| 172 | $confirmationDefault = false; |
||
| 173 | |||
| 174 | $this->ui->write( |
||
| 175 | sprintf( |
||
| 176 | '%sThe script is about to remove <question> %s </question> folders from <info>%s</info>. ', |
||
| 177 | $this->ui->indent(), |
||
| 178 | $nbFoldersToRemove, |
||
| 179 | (string) $downloadPath |
||
| 180 | ) |
||
| 181 | ); |
||
| 182 | } |
||
| 183 | |||
| 184 | $this->ui->write($this->ui->indent()); |
||
| 185 | |||
| 186 | if ($this->skip($this->ui) || !$this->ui->confirm($confirmationDefault)) { |
||
| 187 | $this->ui->writeln(($this->ui->isDryRun() ? '' : PHP_EOL).'<info>Done.</info>'.PHP_EOL); |
||
| 188 | |||
| 189 | return false; |
||
| 190 | } |
||
| 191 | |||
| 192 | return true; |
||
| 193 | } |
||
| 195 |