| Conditions | 14 |
| Paths | 5 |
| Total Lines | 60 |
| Code Lines | 34 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 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); |
||
| 56 | public function handle() |
||
| 57 | { |
||
| 58 | $name = $this->argument('name'); |
||
| 59 | |||
| 60 | $processor = new LaravelProcessor(); |
||
| 61 | |||
| 62 | // parse args |
||
| 63 | $processor->setRunModel($this->option('model') || $this->option('everything')); |
||
| 64 | $processor->setRunMigration($this->option('migration') || $this->option('everything')); |
||
| 65 | $processor->setRunFactory($this->option('factory') || $this->option('everything')); |
||
| 66 | $processor->setRunSeed($this->option('seed') || $this->option('everything')); |
||
| 67 | $processor->setRunPolicy($this->option('policy') || $this->option('everything')); |
||
| 68 | $processor->setRunEvent($this->option('event') || $this->option('everything')); |
||
| 69 | |||
| 70 | // TODO: see issue #2 |
||
| 71 | // generate lighthouse directives |
||
| 72 | // $output = new BufferedOutput(); |
||
| 73 | // $this->call('lighthouse:ide-helper'); |
||
| 74 | // $output->fetch(); |
||
| 75 | |||
| 76 | if ($name === '*' || $name === 'all') { |
||
| 77 | // @phpstan-ignore-next-line |
||
| 78 | $path = base_path('graphql'); |
||
|
|
|||
| 79 | $dir = \Safe\scandir($path); |
||
| 80 | |||
| 81 | // parse directives from lighthouse |
||
| 82 | $modelNames = array_diff($dir, array('.', '..')); |
||
| 83 | $files = [ |
||
| 84 | base_path('schema-directives.graphql'), |
||
| 85 | __DIR__ . '/../../Graphql/definitions.graphql' |
||
| 86 | ]; |
||
| 87 | |||
| 88 | foreach ($modelNames as $n) { |
||
| 89 | if (mb_strpos($n, '.graphql') === false) { |
||
| 90 | continue; |
||
| 91 | } |
||
| 92 | // @phpstan-ignore-next-line |
||
| 93 | $files[] = base_path('graphql/' . $n); |
||
| 94 | } |
||
| 95 | $processor->processFiles($files); |
||
| 96 | } elseif (!$name || is_array($name)) { |
||
| 97 | $this->error('Invalid name parameter'); |
||
| 98 | return; |
||
| 99 | } else { |
||
| 100 | try { |
||
| 101 | $data = \Safe\file_get_contents($this->getPathGraphql($name)); |
||
| 102 | $processor->processString($data); |
||
| 103 | } catch (\Safe\Exceptions\FilesystemException $e) { |
||
| 104 | $this->error("Cannot open model $name"); |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | $this->writeFiles( |
||
| 109 | $processor->getCollection(), |
||
| 110 | // @phpstan-ignore-next-line |
||
| 111 | base_path(), |
||
| 112 | (bool)$this->option('overwrite') |
||
| 113 | ); |
||
| 114 | |||
| 115 | $this->info('Finished. You might want to run `composer dump-autoload`'); |
||
| 116 | } |
||
| 207 |