Conditions | 20 |
Paths | 2592 |
Total Lines | 80 |
Lines | 28 |
Ratio | 35 % |
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 namespace Savannabits\JetstreamInertiaGenerator\Generators; |
||
60 | public function handle() |
||
61 | { |
||
62 | $force = $this->option('force'); |
||
63 | |||
64 | //TODO check if exists |
||
65 | //TODO make global for all generator |
||
66 | //TODO also with prefix |
||
67 | if(!empty($template = $this->option('template'))) { |
||
68 | $this->view = 'templates.'.$template.'.full-form'; |
||
69 | $this->viewJs = 'templates.'.$template.'.form-js'; |
||
70 | } |
||
71 | |||
72 | $this->fileName = $this->option('file-name') ?: $this->modelViewsDirectory; |
||
73 | $this->formJsRelativePath = str_replace([DIRECTORY_SEPARATOR, '/', '\\'], '-', $this->fileName); |
||
74 | if (!$this->option('file-name')) { |
||
75 | $this->fileName = $this->fileName . DIRECTORY_SEPARATOR . 'form'; |
||
76 | } |
||
77 | |||
78 | $this->route = $this->option('route'); |
||
79 | if (!$this->route){ |
||
80 | if ($this->option('file-name')){ |
||
81 | $this->route = 'admin/'.$this->fileName; |
||
82 | } else { |
||
83 | $this->route = 'admin/'.$this->resource.'/update'; |
||
84 | } |
||
85 | } |
||
86 | |||
87 | $viewPath = resource_path('views/admin/'.$this->fileName.'.blade.php'); |
||
88 | if ($this->alreadyExists($viewPath) && !$force) { |
||
89 | $this->error('File '.$viewPath.' already exists!'); |
||
90 | } else { |
||
91 | if ($this->alreadyExists($viewPath) && $force) { |
||
92 | $this->warn('File '.$viewPath.' already exists! File will be deleted.'); |
||
93 | $this->files->delete($viewPath); |
||
94 | } |
||
95 | |||
96 | $this->makeDirectory($viewPath); |
||
97 | |||
98 | $this->files->put($viewPath, $this->buildForm()); |
||
99 | |||
100 | $this->info('Generating '.$viewPath.' finished'); |
||
101 | } |
||
102 | |||
103 | $formJsPath = resource_path('js/admin/'.$this->formJsRelativePath.'/Form.js'); |
||
104 | $bootstrapJsPath = resource_path('js/admin/index.js'); |
||
105 | |||
106 | if ($this->alreadyExists($formJsPath) && !$force) { |
||
107 | $this->error('File '.$formJsPath.' already exists!'); |
||
108 | } else { |
||
109 | if ($this->alreadyExists($formJsPath) && $force) { |
||
110 | $this->warn('File '.$formJsPath.' already exists! File will be deleted.'); |
||
111 | $this->files->delete($formJsPath); |
||
112 | } |
||
113 | |||
114 | $this->makeDirectory($formJsPath); |
||
115 | |||
116 | $this->files->put($formJsPath, $this->buildFormJs()); |
||
117 | $this->info('Generating '.$formJsPath.' finished'); |
||
118 | |||
119 | } |
||
120 | |||
121 | $indexJsPath = resource_path('js/admin/'.$this->formJsRelativePath.'/index.js'); |
||
122 | if ($this->alreadyExists($indexJsPath) && !$force) { |
||
123 | $this->error('File '.$indexJsPath.' already exists!'); |
||
124 | } else { |
||
125 | if ($this->alreadyExists($indexJsPath) && $force) { |
||
126 | $this->warn('File '.$indexJsPath.' already exists! File will be deleted.'); |
||
127 | $this->files->delete($indexJsPath); |
||
128 | } |
||
129 | $this->makeDirectory($indexJsPath); |
||
130 | } |
||
131 | |||
132 | if ($this->appendIfNotAlreadyAppended($indexJsPath, "import './Form';".PHP_EOL)){ |
||
133 | $this->info('Appending Form to '.$indexJsPath.' finished'); |
||
134 | }; |
||
135 | if ($this->appendIfNotAlreadyAppended($bootstrapJsPath, "import './". $this->formJsRelativePath ."';".PHP_EOL)){ |
||
136 | $this->info('Appending '.$this->formJsRelativePath.'/index.js to '.$bootstrapJsPath.' finished'); |
||
137 | }; |
||
138 | |||
139 | } |
||
140 | |||
186 |