Conditions | 12 |
Paths | 8 |
Total Lines | 66 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 5 | ||
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 declare(strict_types=1); |
||
131 | protected function generateFromModel(string $name): void |
||
132 | { |
||
133 | $composer = FrameworkComposer::create($this->frameworks); |
||
134 | $model = $name::getFormularium(); |
||
135 | |||
136 | $generator = new FrontendGenerator($composer, $model, $this->parser); |
||
137 | $collection = $generator->generate(); |
||
138 | |||
139 | if (!$collection->count()) { |
||
140 | $this->info('Nothing generated.'); |
||
141 | return; |
||
142 | } |
||
143 | |||
144 | /** |
||
145 | * @var string $match |
||
146 | */ |
||
147 | $match = $this->option('overwrite-match'); |
||
148 | if (!empty($match)) { |
||
149 | if (!is_string($match)) { |
||
150 | $this->error('--overwrite-match must be a string'); |
||
151 | throw new Exception(''); |
||
152 | } |
||
153 | } |
||
154 | |||
155 | $basepath = base_path('resources/js/components/'); |
||
156 | $writtenFiles = $this->writeFiles( |
||
157 | $collection, |
||
158 | $basepath, |
||
159 | function (GeneratedItem $i) use ($match) { |
||
160 | if ((bool)$this->option('overwrite') === true) { |
||
161 | return true; |
||
162 | } |
||
163 | if ((bool)$this->option('overwrite-graphql') === true) { |
||
164 | if ( |
||
165 | StringUtil::endsWith($i->filename, '.graphql') |
||
166 | ) { |
||
167 | return true; |
||
168 | } elseif (StringUtil::endsWith($i->filename, 'model.js')) { |
||
169 | return true; |
||
170 | } |
||
171 | } |
||
172 | if ($match && mb_strpos($i->filename, $match) !== false) { |
||
173 | return true; |
||
174 | } |
||
175 | return false; |
||
176 | } |
||
177 | ); |
||
178 | $this->info('Files generated.'); |
||
179 | |||
180 | if ($this->option('prettier')) { |
||
181 | $this->info('Running prettier on generated files.'); |
||
182 | $useYarn = file_exists(base_path('yarn.lock')); |
||
183 | if ($useYarn) { |
||
184 | $command = "cd $basepath && npx prettier --write "; |
||
185 | } else { |
||
186 | $command = "cd $basepath && yarn prettier --write "; |
||
187 | } |
||
188 | |||
189 | // this runs all prettier commands in parallel. |
||
190 | $run = array_reduce( |
||
191 | $writtenFiles, |
||
192 | function ($carry, $f) use ($command) { |
||
193 | return $carry . '(' . $command . $f . ') & '; |
||
194 | } |
||
195 | ); |
||
196 | shell_exec($run . ' wait'); |
||
197 | } |
||
200 |