| Conditions | 4 |
| Paths | 5 |
| Total Lines | 60 |
| 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 |
||
| 170 | protected function buildActionPromise() |
||
| 171 | { |
||
| 172 | call_user_func([$this->action, 'dialog']); |
||
| 173 | |||
| 174 | $route = $this->action->getHandleRoute(); |
||
| 175 | $settings = $this->formatSettings(); |
||
| 176 | $calledClass = $this->action->getCalledClass(); |
||
| 177 | |||
| 178 | if ($this->uploadFile) { |
||
| 179 | return $this->buildUploadFileActionPromise($settings, $calledClass, $route); |
||
|
|
|||
| 180 | } |
||
| 181 | |||
| 182 | $controller = ''; |
||
| 183 | if (request()->route()) { |
||
| 184 | $controller = request()->route()->getController(); |
||
| 185 | } |
||
| 186 | if ($controller) { |
||
| 187 | $controller = str_replace('\\', '_', get_class($controller)); |
||
| 188 | } |
||
| 189 | |||
| 190 | return <<<PROMISE |
||
| 191 | var process = $.admin.swal({ |
||
| 192 | {$settings}, |
||
| 193 | preConfirm: function(input) { |
||
| 194 | return new Promise(function(resolve, reject) { |
||
| 195 | Object.assign(data, { |
||
| 196 | _token: $.admin.token, |
||
| 197 | _action: '$calledClass', |
||
| 198 | _controller: '$controller', |
||
| 199 | _input: input, |
||
| 200 | }); |
||
| 201 | |||
| 202 | $.ajax({ |
||
| 203 | method: '{$this->action->getMethod()}', |
||
| 204 | url: '$route', |
||
| 205 | data: data, |
||
| 206 | success: function (data) { |
||
| 207 | resolve(data); |
||
| 208 | }, |
||
| 209 | error:function(request){ |
||
| 210 | reject(request); |
||
| 211 | } |
||
| 212 | }); |
||
| 213 | }); |
||
| 214 | } |
||
| 215 | }).then(function(result) { |
||
| 216 | if (typeof result.dismiss !== 'undefined') { |
||
| 217 | return Promise.reject(); |
||
| 218 | } |
||
| 219 | |||
| 220 | if (typeof result.status === "boolean") { |
||
| 221 | var response = result; |
||
| 222 | } else { |
||
| 223 | var response = result.value; |
||
| 224 | } |
||
| 225 | |||
| 226 | return [response, target]; |
||
| 227 | }); |
||
| 228 | PROMISE; |
||
| 229 | } |
||
| 230 | |||
| 276 |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.