Passed
Push — master ( 52f049...d98d70 )
by Plamen
01:50
created

trait_table_request::request()   C

Complexity

Conditions 14
Paths 1

Size

Total Lines 62
Code Lines 41

Duplication

Lines 0
Ratio 0 %

Importance

Changes 3
Bugs 0 Features 0
Metric Value
cc 14
eloc 41
c 3
b 0
f 0
nc 1
nop 1
dl 0
loc 62
rs 6.2666

How to fix   Long Method    Complexity   

Long Method

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:

1
<?php
2
3
trait trait_table_request
4
{
5
6
    /*private static function requestFilter()
7
    {
8
        $filter = filter_input(INPUT_GET, 'filter') ?: false;
9
        if ($filter) {
10
            $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT);
11
            if ($by === false || is_null($by)) {
12
                $by = self::requestFilterByAll();
13
            } else {
14
                $by = self::$cols[$by][1];
15
            }
16
            $by = 'CONCAT(" ",' . $by . ', " ")';
17
            if (self::config('FILTER_CASE_SENSITIVE') !== true) {
18
                $by .= ' COLLATE ' . self::config('DB_COLLATION_CI');
19
            }
20
            $filter = $by . ' LIKE ' . '"%' . $filter . '%"';
21
        }
22
        return $filter;
23
    }
24
25
    private static function requestFilterByAll()
26
    {
27
        $by = [];
28
        foreach (self::$cols as $v) {
29
            if (isset($v[2]['sort']) && $v[2]['sort'] === false) {
30
                continue;
31
            }
32
            $by[] = 'IFNULL(' . $v[1] . ', "")';
33
        }
34
        return 'CONCAT(' . implode(',', $by) . ')';
35
    }
36
37
    private static function requestOrderCol()
38
    {
39
        if (($col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT))) {
40
            return isset(self::$cols[$col][2]['sort']) ?
41
                    self::$cols[$col][2]['sort'] :
42
                    self::$cols[$col][1];
43
        }
44
        return self::$t['order']['col'];
45
    }
46
47
    private static function requestOrderDir()
48
    {
49
        $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null;
50
        return in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ?
51
                filter_input(INPUT_GET, 'ord') :
52
                ($reset ?: self::$t['order']['dir']);
53
    }
54
55
    private static function requestExport()
56
    {
57
        $exp = filter_input(INPUT_GET, 'export', FILTER_SANITIZE_STRING);
58
        return in_array($exp, self::config('SAVES')) ? $exp : false;
59
    }
60
61
    private static function requestPage()
62
    {
63
        return filter_has_var(INPUT_GET, 'pg') && self::$export == false ?
64
                (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) :
65
                self::$t['page'];
66
    }*/
67
68
    protected static function request($make = null)
0 ignored issues
show
Unused Code introduced by
The parameter $make is not used and could be removed. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-unused  annotation

68
    protected static function request(/** @scrutinizer ignore-unused */ $make = null)

This check looks for parameters that have been defined for a function or method, but which are not used in the method body.

Loading history...
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();
0 ignored issues
show
Bug Best Practice introduced by
The property export does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
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
    }
131
}
132