Conditions | 6 |
Paths | 7 |
Total Lines | 61 |
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 |
||
94 | public function indexAction(Request $request, $name) { |
||
95 | |||
96 | // Get the provider. |
||
97 | $dtProvider = $this->getDataTablesProvider($name); |
||
98 | |||
99 | // Get the wrapper. |
||
100 | $dtWrapper = $this->getDataTablesWrapper($dtProvider); |
||
101 | |||
102 | // Check if the request is an XML HTTP request. |
||
103 | if (false === $request->isXmlHttpRequest()) { |
||
104 | |||
105 | // Get and check the provider view. |
||
106 | $dtView = $dtProvider->getView(); |
||
107 | if (null === $dtProvider->getView()) { |
||
108 | $dtView = "@JQueryDataTables/DataTables/index.html.twig"; |
||
109 | } |
||
110 | |||
111 | // Return the response. |
||
112 | return $this->render($dtView, [ |
||
113 | "dtWrapper" => $dtWrapper, |
||
114 | ]); |
||
115 | } |
||
116 | |||
117 | // Parse the request. |
||
118 | $dtWrapper->parse($request); |
||
119 | |||
120 | // Get the entities repository. |
||
121 | $repository = $this->getDataTablesRepository($dtProvider); |
||
122 | |||
123 | // |
||
124 | $filtered = $repository->dataTablesCountFiltered($dtWrapper); |
||
125 | $total = $repository->dataTablesCountTotal($dtWrapper); |
||
126 | $entities = $repository->dataTablesFindAll($dtWrapper); |
||
127 | |||
128 | // Set the response. |
||
129 | $dtWrapper->getResponse()->setRecordsFiltered($filtered); |
||
130 | $dtWrapper->getResponse()->setRecordsTotal($total); |
||
131 | |||
132 | // Handle each entity. |
||
133 | foreach ($entities as $entity) { |
||
134 | |||
135 | // Count the rows. |
||
136 | $rows = $dtWrapper->getResponse()->countRows(); |
||
137 | |||
138 | // Create a row. |
||
139 | $dtWrapper->getResponse()->addRow(); |
||
140 | |||
141 | // Render each optional parameter. |
||
142 | foreach (DataTablesResponse::dtRow() as $dtRow) { |
||
143 | $dtWrapper->getResponse()->setRow($dtRow, $dtProvider->renderRow($dtRow, $entity, $rows)); |
||
144 | } |
||
145 | |||
146 | // Render each column. |
||
147 | foreach ($dtWrapper->getColumns() as $dtColumn) { |
||
148 | $dtWrapper->getResponse()->setRow($dtColumn->getData(), $dtProvider->renderColumn($dtColumn, $entity)); |
||
149 | } |
||
150 | } |
||
151 | |||
152 | // Return the response. |
||
153 | return new Response(json_encode($dtWrapper->getResponse())); |
||
154 | } |
||
155 | |||
157 |