| Conditions | 7 |
| Paths | 8 |
| Total Lines | 69 |
| Code Lines | 27 |
| 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 |
||
| 137 | public function indexAction(Request $request, $name) { |
||
| 138 | |||
| 139 | // Get the provider. |
||
| 140 | $dtProvider = $this->getDataTablesProvider($name); |
||
| 141 | |||
| 142 | // Get the wrapper. |
||
| 143 | $dtWrapper = $this->getDataTablesWrapper($dtProvider); |
||
| 144 | |||
| 145 | // Check if the request is an XML HTTP request. |
||
| 146 | if (false === $request->isXmlHttpRequest()) { |
||
| 147 | |||
| 148 | // Initialize the default view. |
||
| 149 | $dtView = "@JQueryDataTables/DataTables/index.html.twig"; |
||
| 150 | |||
| 151 | // Check the provider view. |
||
| 152 | if (null !== $dtProvider->getView()) { |
||
| 153 | $dtView = $dtProvider->getView(); |
||
| 154 | } |
||
| 155 | |||
| 156 | // Return the response. |
||
| 157 | return $this->render($dtView, [ |
||
| 158 | "dtWrapper" => $dtWrapper, |
||
| 159 | ]); |
||
| 160 | } |
||
| 161 | |||
| 162 | // Get the entities manager. |
||
| 163 | $em = $this->getDoctrine()->getManager(); |
||
| 164 | |||
| 165 | // Get and check the entities repository. |
||
| 166 | $repository = $em->getRepository($dtProvider->getEntity()); |
||
| 167 | if (false === ($repository instanceOf DataTablesRepositoryInterface)) { |
||
| 168 | throw new BadDataTablesRepositoryException($repository); |
||
| 169 | } |
||
| 170 | |||
| 171 | // Parse the request. |
||
| 172 | $dtWrapper->parse($request); |
||
| 173 | |||
| 174 | // |
||
| 175 | $filtered = $repository->dataTablesCountFiltered($dtWrapper); |
||
| 176 | $total = $repository->dataTablesCountTotal($dtWrapper); |
||
| 177 | $entities = $repository->dataTablesFindAll($dtWrapper); |
||
| 178 | |||
| 179 | // Set the response. |
||
| 180 | $dtWrapper->getResponse()->setRecordsFiltered($filtered); |
||
| 181 | $dtWrapper->getResponse()->setRecordsTotal($total); |
||
| 182 | |||
| 183 | // Handle each entity. |
||
| 184 | foreach ($entities as $entity) { |
||
| 185 | |||
| 186 | // Count the rows. |
||
| 187 | $rows = $dtWrapper->getResponse()->countRows(); |
||
| 188 | |||
| 189 | // Create a row. |
||
| 190 | $dtWrapper->getResponse()->addRow(); |
||
| 191 | |||
| 192 | // Render each optional parameters. |
||
| 193 | foreach (DataTablesResponse::dtRow() as $dtRow) { |
||
| 194 | $dtWrapper->getResponse()->setRow($dtRow, $dtProvider->renderRow($dtRow, $entity, $rows)); |
||
| 195 | } |
||
| 196 | |||
| 197 | // Render each column. |
||
| 198 | foreach ($dtWrapper->getColumns() as $dtColumn) { |
||
| 199 | $dtWrapper->getResponse()->setRow($dtColumn->getData(), $dtProvider->renderColumn($dtColumn, $entity)); |
||
| 200 | } |
||
| 201 | } |
||
| 202 | |||
| 203 | // Return the response. |
||
| 204 | return new Response(json_encode($dtWrapper->getResponse())); |
||
| 205 | } |
||
| 206 | |||
| 208 |
It seems like the type of the argument is not accepted by the function/method which you are calling.
In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.
We suggest to add an explicit type cast like in the following example: