| Conditions | 15 | 
| Paths | 15 | 
| Total Lines | 61 | 
| 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 | ||
| 50 | public function handleRequest(FormInterface $form, $request = null) | ||
| 51 |     { | ||
| 52 |         if (!$request instanceof Request) { | ||
| 53 | throw new UnexpectedTypeException($request, 'Symfony\Component\HttpFoundation\Request'); | ||
| 54 | } | ||
| 55 | |||
| 56 | $name = $form->getName(); | ||
| 57 | $method = $request->getMethod(); | ||
| 58 | |||
| 59 | // For request methods that must not have a request body we fetch data | ||
| 60 | // from the query string. Otherwise we look for data in the request body. | ||
| 61 |         if ('GET' === $method || 'HEAD' === $method || 'TRACE' === $method) { | ||
| 62 |             if ('' === $name) { | ||
| 63 | $data = $request->query->all(); | ||
| 64 |             } else { | ||
| 65 | // Don't submit GET requests if the form's name does not exist | ||
| 66 | // in the request | ||
| 67 |                 if (!$request->query->has($name)) { | ||
| 68 | return; | ||
| 69 | } | ||
| 70 | |||
| 71 | $data = $request->query->get($name); | ||
| 72 | } | ||
| 73 |         } else { | ||
| 74 | // Mark the form with an error if the uploaded size was too large | ||
| 75 | // This is done here and not in FormValidator because $_POST is | ||
| 76 | // empty when that error occurs. Hence the form is never submitted. | ||
| 77 |             if ($this->serverParams->hasPostMaxSizeBeenExceeded()) { | ||
| 78 | // Submit the form, but don't clear the default values | ||
| 79 | $form->submit(null, false); | ||
| 80 | |||
| 81 | $form->addError(new FormError( | ||
| 82 |                     call_user_func($form->getConfig()->getOption('upload_max_size_message')), | ||
| 83 | null, | ||
| 84 |                     ['{{ max }}' => $this->serverParams->getNormalizedIniPostMaxSize()] | ||
| 85 | )); | ||
| 86 | |||
| 87 | return; | ||
| 88 | } | ||
| 89 | |||
| 90 |             if ('' === $name) { | ||
| 91 | $params = $request->request->all(); | ||
| 92 | $files = $request->files->all(); | ||
| 93 |             } elseif ($request->request->has($name) || $request->files->has($name)) { | ||
| 94 | $default = $form->getConfig()->getCompound() ? [] : null; | ||
| 95 | $params = $request->request->get($name, $default); | ||
| 96 | $files = $request->files->get($name, $default); | ||
| 97 |             } else { | ||
| 98 | // Don't submit the form if it is not present in the request | ||
| 99 | return; | ||
| 100 | } | ||
| 101 | |||
| 102 |             if (is_array($params) && is_array($files)) { | ||
| 103 | $data = array_replace_recursive($params, $files); | ||
| 104 |             } else { | ||
| 105 | $data = $params ?: $files; | ||
| 106 | } | ||
| 107 | } | ||
| 108 | |||
| 109 | $form->submit($data, 'PATCH' !== $method); | ||
| 110 | } | ||
| 111 | |||
| 117 |