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