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