Conditions | 17 |
Paths | 36 |
Total Lines | 83 |
Code Lines | 37 |
Lines | 0 |
Ratio | 0 % |
Changes | 4 | ||
Bugs | 2 | 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); |
||
66 | public function handle() |
||
67 | { |
||
68 | $name = $this->argument('name'); |
||
69 | |||
70 | $processor = new LaravelProcessor(); |
||
71 | |||
72 | // parse args |
||
73 | $processor->setRunModel($this->option('model') || $this->option('everything')); |
||
74 | $processor->setRunMigration($this->option('migration') || $this->option('everything')); |
||
75 | $processor->setRunFactory($this->option('factory') || $this->option('everything')); |
||
76 | $processor->setRunSeed($this->option('seed') || $this->option('everything')); |
||
77 | $processor->setRunPolicy($this->option('policy') || $this->option('everything')); |
||
78 | $processor->setRunEvent($this->option('event') || $this->option('everything')); |
||
79 | |||
80 | if ($this->option('modelDir') && is_string($this->option('modelDir'))) { |
||
81 | ModelGenerator::setModelDir($this->option('modelDir')); |
||
82 | } elseif ($this->modelariumOptions->getOption('modelarium', 'modelDir')) { |
||
83 | ModelGenerator::setModelDir($this->modelariumOptions->getOption('modelarium', 'modelDir')); |
||
84 | } |
||
85 | |||
86 | // this generates the missing types and fills them, but it loses the directives. |
||
87 | // if ($this->option('lighthouse')) { |
||
88 | // $output = new BufferedOutput(); |
||
89 | // $this->runCommand( |
||
90 | // 'lighthouse:print', |
||
91 | // [], |
||
92 | // $output |
||
93 | // ); |
||
94 | // $processor->processString($output->fetch()); |
||
95 | // SchemaPrinter::printFilteredSchema( |
||
96 | // $schema, |
||
97 | // static function ($type) : bool { |
||
98 | // return ! Directive::isSpecifiedDirective($type); |
||
99 | // }, |
||
100 | // static function ($type) : bool { |
||
101 | // return ! Type::isBuiltInType($type); |
||
102 | // }, |
||
103 | // $options |
||
104 | // ); |
||
105 | // } else { |
||
106 | |||
107 | $files = [ |
||
108 | __DIR__ . '/../../../Types/Graphql/scalars.graphql' |
||
109 | ]; |
||
110 | |||
111 | if ($this->option('lighthouse') ?? $this->modelariumOptions->getOption('modelarium', 'lighthouse')) { |
||
112 | $files[] = __DIR__ . '/../../Graphql/definitionsLighthouse.graphql'; |
||
113 | } |
||
114 | |||
115 | $path = base_path('graphql'); |
||
116 | $dir = \Safe\scandir($path); |
||
117 | |||
118 | // parse directives from lighthouse |
||
119 | $modelNames = array_diff($dir, array('.', '..')); |
||
120 | |||
121 | foreach ($modelNames as $n) { |
||
122 | if (mb_strpos($n, '.graphql') === false) { |
||
123 | continue; |
||
124 | } |
||
125 | $files[] = base_path('graphql/' . $n); |
||
126 | } |
||
127 | $processor->processFiles($files); |
||
128 | |||
129 | |||
130 | $files = $processor->getCollection(); |
||
131 | if ($name && $name !== '*' && $name !== 'all') { |
||
132 | $files = $files->filter( |
||
133 | function (GeneratedItem $g) use ($name) { |
||
134 | if (is_array($name)) { |
||
135 | throw new \Exception('Arrays not supported yet'); |
||
136 | } else { |
||
137 | return mb_stripos($g->filename, $name); |
||
138 | } |
||
139 | } |
||
140 | ); |
||
141 | } |
||
142 | |||
143 | $this->writeFiles( |
||
144 | $files, |
||
145 | base_path(), |
||
146 | (bool)$this->option('overwrite') |
||
147 | ); |
||
148 | $this->info('Finished scaffolding. You might want to run `composer dump-autoload`'); |
||
149 | } |
||
156 |