| Conditions | 12 |
| Paths | 216 |
| Total Lines | 85 |
| 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 |
||
| 35 | public function getRules() |
||
| 36 | { |
||
| 37 | $request = $this->getRequest(); |
||
| 38 | |||
| 39 | $requestSearchValue = $request->get('search') ? '%' . $request->get('search')['value'] . '%' : ""; |
||
| 40 | $recordsTotal = RewriteurlRuleQuery::create()->count(); |
||
| 41 | $search = RewriteurlRuleQuery::create(); |
||
| 42 | if ("" !== $requestSearchValue) { |
||
| 43 | $search |
||
| 44 | ->filterByValue($requestSearchValue, Criteria::LIKE) |
||
| 45 | ->_or() |
||
| 46 | ->filterByRedirectUrl($requestSearchValue) |
||
| 47 | ; |
||
| 48 | } |
||
| 49 | |||
| 50 | $recordsFiltered = $search->count(); |
||
| 51 | |||
| 52 | $search->clearOrderByColumns(); |
||
| 53 | switch ($request->get('order')[0]['column']) { |
||
| 54 | case '0': |
||
| 55 | $search->orderByRuleType($request->get('order')[0]['dir']); |
||
| 56 | break; |
||
| 57 | case '1': |
||
| 58 | $search->orderByValue($request->get('order')[0]['dir']); |
||
| 59 | break; |
||
| 60 | case '2': |
||
| 61 | $search->orderByOnly404($request->get('order')[0]['dir']); |
||
| 62 | break; |
||
| 63 | case '3': |
||
| 64 | $search->orderByRedirectUrl($request->get('order')[0]['dir']); |
||
| 65 | break; |
||
| 66 | case '4': |
||
| 67 | $search->orderByPosition($request->get('order')[0]['dir']); |
||
| 68 | break; |
||
| 69 | default: |
||
| 70 | $search->orderByPosition(); |
||
| 71 | break; |
||
| 72 | } |
||
| 73 | |||
| 74 | $search |
||
| 75 | ->offset($request->get('start')) |
||
| 76 | ->limit($request->get('length')) |
||
| 77 | ; |
||
| 78 | $searchArray = $search->find()->toArray(); |
||
| 79 | |||
| 80 | $resultsArray = []; |
||
| 81 | foreach ($searchArray as $row) { |
||
| 82 | $id = $row['Id']; |
||
| 83 | $isRegexSelected = $row['RuleType'] === 'regex' ? 'selected' : ''; |
||
| 84 | $isParamsSelected = $row['RuleType'] === 'params' ? 'selected' : ''; |
||
| 85 | $isOnly404Checked = $row['Only404'] ? 'checked' : ''; |
||
| 86 | $rewriteUrlRuleParams = RewriteurlRuleQuery::create()->findPk($row['Id'])->getRewriteUrlParamCollection(); |
||
| 87 | $resultsArray[] = [ |
||
| 88 | 'Id' => $row['Id'], |
||
| 89 | 'RuleType' => '<select class="js_rule_type form-control" data-idrule="' . $id . '" required> |
||
| 90 | <option value="regex" ' . $isRegexSelected . '>' . Translator::getInstance()->trans("Regex", [], RewriteUrl::MODULE_DOMAIN) . '</option> |
||
| 91 | <option value="params" ' . $isParamsSelected . '>' . Translator::getInstance()->trans("Get Params", [], RewriteUrl::MODULE_DOMAIN) . '</option> |
||
| 92 | </select>', |
||
| 93 | 'Value' => $this->renderRaw( |
||
| 94 | "RewriteUrl/tab-value-render", |
||
| 95 | [ |
||
| 96 | "REWRITE_URL_PARAMS" => $rewriteUrlRuleParams, |
||
| 97 | "VALUE" => $row['Value'], |
||
| 98 | ] |
||
| 99 | ), |
||
| 100 | 'Only404' => '<input class="js_only404 form-control" type="checkbox" style="width: 100%!important;" ' . $isOnly404Checked . '/>', |
||
| 101 | 'RedirectUrl' => '<div class="col-md-12 input-group"> |
||
| 102 | <input class="js_url_to_redirect form-control" type="text" placeholder="/path/mypage.html" value="' . $row['RedirectUrl'] . '"/> |
||
| 103 | </div>', |
||
| 104 | 'Position' => '<a href="#" class="u-position-up js_move_rule_position_up" data-idrule="' . $id . '"><i class="glyphicon glyphicon-arrow-up"></i></a> |
||
| 105 | <span class="js_editable_rule_position editable editable-click" data-idrule="' . $id . '">' . $row['Position'] . '</span> |
||
| 106 | <a href="#" class="u-position-down js_move_rule_position_down" data-idrule="' . $id . '"><i class="glyphicon glyphicon-arrow-down"></i></a>', |
||
| 107 | 'Actions' => '<a href="#" class="js_btn_update_rule btn btn-success" data-idrule="' . $id . '"><span class="glyphicon glyphicon-check"></span></a> |
||
| 108 | <a href="#" class="js_btn_remove_rule btn btn-danger" data-idrule="' . $id . '"><span class="glyphicon glyphicon-remove"></span></a> |
||
| 109 | ', |
||
| 110 | ]; |
||
| 111 | } |
||
| 112 | |||
| 113 | return new JsonResponse([ |
||
| 114 | 'draw' => $request->get('draw'), |
||
| 115 | 'recordsTotal' => $recordsTotal, |
||
| 116 | 'recordsFiltered' => $recordsFiltered, |
||
| 117 | 'data' => $resultsArray |
||
| 118 | ]); |
||
| 119 | } |
||
| 120 | |||
| 297 |