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