| Conditions | 2 |
| Paths | 2 |
| Total Lines | 65 |
| Code Lines | 45 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 18 | public function __invoke(string $name, InputInterface $input, OutputInterface $output) |
||
| 19 | { |
||
| 20 | $output->writeln('<info># Installing Ide Helper...</info>'); |
||
| 21 | |||
| 22 | $directory = getcwd() . '/' . $name; |
||
| 23 | |||
| 24 | $composer = $this->findComposer(); |
||
| 25 | |||
| 26 | $commands = [ |
||
| 27 | $composer . ' require --dev barryvdh/laravel-ide-helper doctrine/dbal', |
||
| 28 | 'php artisan vendor:publish --provider="Barryvdh\LaravelIdeHelper\IdeHelperServiceProvider" --tag=config', |
||
| 29 | ]; |
||
| 30 | |||
| 31 | $runner = new CommandRunner($output, $directory); |
||
| 32 | $runner->run($commands); |
||
| 33 | |||
| 34 | $filesystem = new ProjectFilesystem(getcwd() . '/' . $name); |
||
| 35 | |||
| 36 | $output->writeln('<info>Update file: composer.json</info>'); |
||
| 37 | $filesystem->updateFile('composer.json', function (string $content) { |
||
| 38 | $refreshScript = <<<STRING |
||
| 39 | "refresh": [ |
||
| 40 | "@php artisan migrate:fresh --ansi", |
||
| 41 | "@php artisan db:seed --ansi", |
||
| 42 | "@php artisan ide-helper:models -W -R --ansi" |
||
| 43 | ], |
||
| 44 | "post-update-cmd": [ |
||
| 45 | "Illuminate\\\\\\\\Foundation\\\\\\\\ComposerScripts::postUpdate", |
||
| 46 | "php artisan ide-helper:generate", |
||
| 47 | "php artisan ide-helper:meta" |
||
| 48 | ], |
||
| 49 | |||
| 50 | STRING; |
||
| 51 | $patterns = [ |
||
| 52 | '/("scripts": {\n)/', |
||
| 53 | ]; |
||
| 54 | $replace = [ |
||
| 55 | '${1}' . $refreshScript, |
||
| 56 | ]; |
||
| 57 | |||
| 58 | return preg_replace($patterns, $replace, $content); |
||
| 59 | }); |
||
| 60 | |||
| 61 | $output->writeln('<info>Update file: config/ide-helper.php</info>'); |
||
| 62 | $filesystem->updateFile('config/ide-helper.php', function (string $content) { |
||
| 63 | $patterns = [ |
||
| 64 | '/\'include_fluent\' => false,/', |
||
| 65 | '/\'include_factory_builders\' => false,/', |
||
| 66 | '/\'write_model_magic_where\' => true,/', |
||
| 67 | '/\'write_eloquent_model_mixins\' => false,/', |
||
| 68 | ]; |
||
| 69 | $replace = [ |
||
| 70 | '\'include_fluent\' => true,', |
||
| 71 | '\'include_factory_builders\' => true,', |
||
| 72 | '\'write_model_magic_where\' => false,', |
||
| 73 | '\'write_eloquent_model_mixins\' => true,', |
||
| 74 | ]; |
||
| 75 | |||
| 76 | return preg_replace($patterns, $replace, $content); |
||
| 77 | }); |
||
| 78 | |||
| 79 | $isSuccessful = $runner->run([$composer . ' update']); |
||
| 80 | |||
| 81 | if ($isSuccessful) { |
||
| 82 | $output->writeln('<comment>Ide Helper installed.</comment>'); |
||
| 83 | } |
||
| 102 |