| Conditions | 17 |
| Paths | 1 |
| Total Lines | 67 |
| Code Lines | 48 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| 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 |
||
| 127 | protected static function request() |
||
| 128 | { |
||
| 129 | $export = function(){ |
||
| 130 | $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING); |
||
| 131 | return in_array($exp, self::config('SAVES')) ? $exp : false; |
||
|
|
|||
| 132 | }; |
||
| 133 | $order_dir = function(){ |
||
| 134 | $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null; |
||
| 135 | return |
||
| 136 | in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ? |
||
| 137 | filter_input(INPUT_GET, 'ord') : |
||
| 138 | ($reset ?: self::$t['order']['dir']); |
||
| 139 | }; |
||
| 140 | $order_col = function(){ |
||
| 141 | $col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT); |
||
| 142 | if ($col) { |
||
| 143 | return isset(self::$cols[$col][2]['sort']) ? |
||
| 144 | self::$cols[$col][2]['sort'] : |
||
| 145 | self::$cols[$col][1]; |
||
| 146 | } |
||
| 147 | return self::$t['order']['col']; |
||
| 148 | }; |
||
| 149 | $filter = function(){ |
||
| 150 | $filter = filter_input(INPUT_GET, 'filter') ?: false; |
||
| 151 | $filterByAll = function(){ |
||
| 152 | $by = []; |
||
| 153 | foreach (self::$cols as $v) { |
||
| 154 | if (isset($v[2]['sort']) && $v[2]['sort'] === false) { |
||
| 155 | continue; |
||
| 156 | } |
||
| 157 | $by[] = 'IFNULL(' . $v[1] . ', "")'; |
||
| 158 | } |
||
| 159 | return 'CONCAT(' . implode(',', $by) . ')'; |
||
| 160 | }; |
||
| 161 | if ($filter) { |
||
| 162 | $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT); |
||
| 163 | if ($by === false || is_null($by)) { |
||
| 164 | $by = $filterByAll(); |
||
| 165 | } else { |
||
| 166 | $by = self::$cols[$by][1]; |
||
| 167 | } |
||
| 168 | $by = 'CONCAT(" ",' . $by . ', " ")'; |
||
| 169 | if (self::config('FILTER_CASE_SENSITIVE') !== true) { |
||
| 170 | $by .= ' COLLATE ' . self::config('DB_COLLATION_CI'); |
||
| 171 | } |
||
| 172 | $filter = $by . ' LIKE ' . '"%' . $filter . '%"'; |
||
| 173 | } |
||
| 174 | return $filter; |
||
| 175 | }; |
||
| 176 | $page = function(){ |
||
| 177 | return filter_has_var(INPUT_GET, 'pg') && self::$export == false ? |
||
| 178 | (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : |
||
| 179 | self::$t['page']; |
||
| 180 | }; |
||
| 181 | |||
| 182 | self::$export = $export(); |
||
| 183 | |||
| 184 | $t = [ |
||
| 185 | 'order' => [ |
||
| 186 | 'dir' => $order_dir(), |
||
| 187 | 'col' => $order_col() |
||
| 188 | ], |
||
| 189 | 'filter' => $filter(), |
||
| 190 | 'page' => $page() |
||
| 191 | ]; |
||
| 192 | //dd(array_merge(self::$t, $t)); |
||
| 193 | return array_merge(self::$t, $t); |
||
| 194 | } |
||
| 196 |