| Conditions | 5 |
| Paths | 4 |
| Total Lines | 51 |
| Code Lines | 31 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 2 | ||
| 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 |
||
| 55 | public function handle() |
||
| 56 | { |
||
| 57 | $models = $this->getModelsThatShouldBeInspected(); |
||
| 58 | |||
| 59 | $this->info("Found {$models->count()} models."); |
||
| 60 | $this->info("Inspecting model relations."); |
||
| 61 | |||
| 62 | $bar = $this->output->createProgressBar($models->count()); |
||
| 63 | |||
| 64 | $models->transform(function ($model) use ($bar) { |
||
| 65 | $bar->advance(); |
||
| 66 | return new GraphModel( |
||
| 67 | $model, |
||
| 68 | (new ReflectionClass($model))->getShortName(), |
||
| 69 | $this->relationFinder->getModelRelations($model) |
||
| 70 | ); |
||
| 71 | }); |
||
| 72 | |||
| 73 | // If structured text output is requested, generate it |
||
| 74 | if ($this->option('structured')) { |
||
| 75 | $textOutput = $this->graphBuilder->generateStructuredTextRepresentation($models); |
||
| 76 | $outputFileName = $this->getTextOutputFileName(); |
||
| 77 | file_put_contents($outputFileName, $textOutput); |
||
| 78 | $this->info(PHP_EOL); |
||
| 79 | $this->info('Wrote structured text diagram to ' . $outputFileName); |
||
| 80 | return; |
||
| 81 | } |
||
| 82 | |||
| 83 | $graph = $this->graphBuilder->buildGraph($models); |
||
| 84 | |||
| 85 | if ($this->option('text-output') || $this->option('format') === self::FORMAT_TEXT) { |
||
| 86 | $textOutput = $graph->__toString(); |
||
| 87 | |||
| 88 | // If text-output option is set, write to file |
||
| 89 | if ($this->option('text-output')) { |
||
| 90 | $outputFileName = $this->getTextOutputFileName(); |
||
| 91 | file_put_contents($outputFileName, $textOutput); |
||
| 92 | $this->info(PHP_EOL); |
||
| 93 | $this->info('Wrote text diagram to ' . $outputFileName); |
||
| 94 | return; |
||
| 95 | } |
||
| 96 | |||
| 97 | // Otherwise just output to console |
||
| 98 | $this->info($textOutput); |
||
| 99 | return; |
||
| 100 | } |
||
| 101 | |||
| 102 | $graph->export($this->option('format'), $this->getOutputFileName()); |
||
| 103 | |||
| 104 | $this->info(PHP_EOL); |
||
| 105 | $this->info('Wrote diagram to ' . $this->getOutputFileName()); |
||
| 106 | } |
||
| 137 |