| Conditions | 10 |
| Paths | 31 |
| Total Lines | 46 |
| Code Lines | 23 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 0 |
| CRAP Score | 110 |
| 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 |
||
| 23 | public function process(FilesCollection $files, Report $report) { |
||
| 24 | |||
| 25 | if (empty($this->getTools())) { |
||
| 26 | $this->getOutput()->writeln('<comment>Empty tools list</comment>'); |
||
| 27 | return; |
||
| 28 | } |
||
| 29 | |||
| 30 | $message = '✘ dry run '; |
||
| 31 | if ($this->saveFiles) { |
||
| 32 | $message = '✔ fixed '; |
||
| 33 | } |
||
| 34 | |||
| 35 | foreach ($files as $file) { |
||
| 36 | |||
| 37 | $fixed = false; |
||
| 38 | |||
| 39 | foreach ($this->getTools() as $tool) { |
||
| 40 | |||
| 41 | if ($this->getOutput()->isDebug()) { |
||
| 42 | $this->getOutput()->writeln('process : (' . $tool->getName() . ') ' . $file->getPath()); |
||
| 43 | } |
||
| 44 | |||
| 45 | if (!$tool->canProcess($file)) { |
||
| 46 | continue; |
||
| 47 | } |
||
| 48 | |||
| 49 | $tool->process($file, $report); |
||
| 50 | |||
| 51 | $fileChanged = $file->getContent()->isChanged(); |
||
| 52 | if ($fileChanged === false) { |
||
| 53 | continue; |
||
| 54 | } |
||
| 55 | |||
| 56 | $fixed = true; |
||
| 57 | |||
| 58 | $this->getOutput()->writeln('<info>' . $message . ': ' . $tool->getDescription() . '</info>'); |
||
| 59 | } |
||
| 60 | |||
| 61 | if ($fixed and $this->saveFiles) { |
||
| 62 | $file->save(); |
||
| 63 | $this->getOutput()->writeln('<info>' . '✔ saved : ' . $file->getPath() . '</info>'); |
||
| 64 | } |
||
| 65 | |||
| 66 | } |
||
| 67 | |||
| 68 | } |
||
| 69 | |||
| 86 | } |