Conditions | 14 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 41 |
Lines | 0 |
Ratio | 0 % |
Changes | 3 | ||
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 |
||
68 | protected static function request($make = null) |
||
|
|||
69 | { |
||
70 | $export = function() |
||
71 | { |
||
72 | $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
||
73 | return in_array($exp, self::config('SAVES')) ? $exp : false; |
||
74 | }; |
||
75 | $order_dir = function() |
||
76 | { |
||
77 | $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
||
78 | return |
||
79 | in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
||
80 | filter_input(INPUT_GET, 'ord') : |
||
81 | ($reset ?: self::$t['order']['dir']); |
||
82 | }; |
||
83 | $order_col = function() |
||
84 | { |
||
85 | $col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
||
86 | if ($col) { |
||
87 | return isset(self::$cols[$col][2]['sort']) ? |
||
88 | self::$cols[$col][2]['sort'] : |
||
89 | self::$cols[$col][1]; |
||
90 | } |
||
91 | return self::$t['order']['col']; |
||
92 | }; |
||
93 | $filter = function() |
||
94 | { |
||
95 | $filter = filter_input(INPUT_GET, 'filter') ?: false; |
||
96 | if ($filter) { |
||
97 | $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
||
98 | if ($by === false || is_null($by)) { |
||
99 | $by = self::request('FilterByAll'); |
||
100 | } else { |
||
101 | $by = self::$cols[$by][1]; |
||
102 | } |
||
103 | $by = 'CONCAT(" ",' . $by . ', " ")'; |
||
104 | if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
||
105 | $by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
||
106 | } |
||
107 | $filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
||
108 | } |
||
109 | return $filter; |
||
110 | }; |
||
111 | $page = function() |
||
112 | { |
||
113 | return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
||
114 | (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
||
115 | self::$t['page']; |
||
116 | }; |
||
117 | |||
118 | self::$export = $export(); |
||
119 | |||
120 | $t = [ |
||
121 | 'order' => [ |
||
122 | 'dir' => $order_dir(), |
||
123 | 'col' => $order_col() |
||
124 | ], |
||
125 | 'filter' => $filter(), |
||
126 | 'page' => $page() |
||
127 | ]; |
||
128 | //dd(array_merge(self::$t, $t)); |
||
129 | return array_merge(self::$t, $t); |
||
130 | } |
||
132 |
This check looks for parameters that have been defined for a function or method, but which are not used in the method body.