| Conditions | 15 |
| Paths | 42 |
| Total Lines | 52 |
| 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 |
||
| 17 | public function handle() |
||
| 18 | { |
||
| 19 | if ($this->option('nofix')) { |
||
| 20 | $this->info(PHP_EOL.' Checking for possible code flattenings...'.PHP_EOL); |
||
| 21 | } |
||
| 22 | |||
| 23 | if (! $this->option('nofix') && ! $this->startWarning()) { |
||
| 24 | return; |
||
| 25 | } |
||
| 26 | |||
| 27 | $psr4 = ComposerJson::readAutoload(); |
||
| 28 | |||
| 29 | $fixingFilesCount = $totalNumberOfFixes = $fixedFilesCount = 0; |
||
| 30 | foreach ($psr4 as $psr4Namespace => $psr4Path) { |
||
| 31 | $files = FilePath::getAllPhpFiles($psr4Path); |
||
| 32 | foreach ($files as $file) { |
||
| 33 | $path = $file->getRealPath(); |
||
| 34 | $tokens = token_get_all(file_get_contents($path)); |
||
| 35 | if (empty($tokens) || $tokens[0][0] !== T_OPEN_TAG) { |
||
| 36 | continue; |
||
| 37 | } |
||
| 38 | |||
| 39 | try { |
||
| 40 | [$fixes, $tokens] = $this->refactor($tokens); |
||
|
|
|||
| 41 | } catch (\Exception $e) { |
||
| 42 | dump('(O_o) Well, It seems we had some problem parsing the contents of: (O_o)'); |
||
| 43 | dump('Skipping : '.$path); |
||
| 44 | continue; |
||
| 45 | } |
||
| 46 | |||
| 47 | $fixes !== 0 && $fixingFilesCount++; |
||
| 48 | |||
| 49 | if ($this->option('nofix') && $fixes !== 0) { |
||
| 50 | $filePath = FilePath::getRelativePath($path); |
||
| 51 | $this->line("<fg=red> - $filePath</fg=red>"); |
||
| 52 | continue; |
||
| 53 | } |
||
| 54 | |||
| 55 | if ($fixes == 0 || ! $this->getConfirm($path)) { |
||
| 56 | continue; |
||
| 57 | } |
||
| 58 | |||
| 59 | $this->fix($path, $tokens, $fixes); |
||
| 60 | $fixedFilesCount++; |
||
| 61 | $totalNumberOfFixes += $fixes; |
||
| 62 | } |
||
| 63 | } |
||
| 64 | |||
| 65 | $this->printFinalMsg($fixedFilesCount, $fixingFilesCount); |
||
| 66 | |||
| 67 | return app(ErrorPrinter::class)->hasErrors() ? 1 : 0; |
||
| 68 | } |
||
| 69 | |||
| 117 |
This check marks access to variables or properties that have not been declared yet. While PHP has no explicit notion of declaring a variable, accessing it before a value is assigned to it is most likely a bug.