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