Conditions | 5 |
Paths | 4 |
Total Lines | 52 |
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 | // Check if output filename has .txt extension |
||
74 | $outputFileName = $this->getOutputFileName(); |
||
75 | if (pathinfo($outputFileName, PATHINFO_EXTENSION) === 'txt') { |
||
76 | // Generate structured text output for .txt files |
||
77 | $textOutput = $this->graphBuilder->generateStructuredTextRepresentation($models); |
||
78 | file_put_contents($outputFileName, $textOutput); |
||
79 | $this->info(PHP_EOL); |
||
80 | $this->info('Wrote structured ER diagram to ' . $outputFileName); |
||
81 | return; |
||
82 | } |
||
83 | |||
84 | $graph = $this->graphBuilder->buildGraph($models); |
||
85 | |||
86 | if ($this->option('text-output') || $this->option('format') === self::FORMAT_TEXT) { |
||
87 | $textOutput = $graph->__toString(); |
||
88 | |||
89 | // If text-output option is set, write to file |
||
90 | if ($this->option('text-output')) { |
||
91 | $outputFileName = $this->getTextOutputFileName(); |
||
92 | file_put_contents($outputFileName, $textOutput); |
||
93 | $this->info(PHP_EOL); |
||
94 | $this->info('Wrote text diagram to ' . $outputFileName); |
||
95 | return; |
||
96 | } |
||
97 | |||
98 | // Otherwise just output to console |
||
99 | $this->info($textOutput); |
||
100 | return; |
||
101 | } |
||
102 | |||
103 | $graph->export($this->option('format'), $outputFileName); |
||
104 | |||
105 | $this->info(PHP_EOL); |
||
106 | $this->info('Wrote diagram to ' . $outputFileName); |
||
107 | } |
||
138 |