Passed
Push — master ( a13310...b93b90 )
by Plamen
01:25
created
table_setter.php 1 patch
Spacing   +24 added lines, -27 removed lines patch added patch discarded remove patch
@@ -49,16 +49,16 @@  discard block
 block discarded – undo
49 49
         $list = [];
50 50
         foreach ($attributes as $key => $value) {
51 51
             if (is_bool($value)) {
52
-                if ((bool) $value) {
52
+                if ((bool)$value) {
53 53
                     $list[] = $key;
54 54
                 }
55
-            } else if (empty($value)&&!is_int($value)) {
55
+            } else if (empty($value) && !is_int($value)) {
56 56
                 $list[] = $key;
57 57
             } else {
58 58
                 $list[] = $key . '="' . $value . '"';
59 59
             }
60 60
         }
61
-        return (count($list)>0 ? ' ' : '') . join(' ', $list);
61
+        return (count($list) > 0 ? ' ' : '') . join(' ', $list);
62 62
     }
63 63
 
64 64
     /** Parses view to string
@@ -70,12 +70,12 @@  discard block
 block discarded – undo
70 70
         extract($vars);
71 71
         ob_start();
72 72
         require $template;
73
-        return (string) ob_get_clean();
73
+        return (string)ob_get_clean();
74 74
     }
75 75
 
76 76
     protected static function paging(&$v)
77 77
     {
78
-        if (self::$t['pages']>1) {
78
+        if (self::$t['pages'] > 1) {
79 79
             $v['pages'] = self::$t['pages'];
80 80
             $v['page'] = self::$t['page'];
81 81
             $v['jumpL'] = self::pagingJumps();
@@ -85,12 +85,12 @@  discard block
 block discarded – undo
85 85
 
86 86
             $limit = 10;
87 87
 
88
-            $v['start'] = $v['page']>($limit/2) ? ($v['page']-$limit/2) : 1;
88
+            $v['start'] = $v['page'] > ($limit/2) ? ($v['page'] - $limit/2) : 1;
89 89
 
90
-            if ($v['page']>($v['pages']-($limit/2))) {
90
+            if ($v['page'] > ($v['pages'] - ($limit/2))) {
91 91
                 $v['final'] = $v['pages'];
92
-            } else if ($v['page']>($limit/2)) {
93
-                $v['final'] = $v['start']+$limit;
92
+            } else if ($v['page'] > ($limit/2)) {
93
+                $v['final'] = $v['start'] + $limit;
94 94
             } else {
95 95
                 $v['final'] = $limit;
96 96
             }
@@ -110,9 +110,9 @@  discard block
 block discarded – undo
110 110
             $m = 100;
111 111
         }
112 112
         $jump2show = function($m) use ($direction) {
113
-            if ($m >=1000000) {
113
+            if ($m >= 1000000) {
114 114
                 return ($direction . ($m/1000000) . "M");
115
-            } else if ($m >=1000) {
115
+            } else if ($m >= 1000) {
116 116
                 return ($direction . ($m/1000) . "K");
117 117
             } else {
118 118
                 return ($direction . $m);
@@ -120,14 +120,14 @@  discard block
 block discarded – undo
120 120
         };
121 121
         $add = '<li class="jump"><a>' . $jump2show($m) . '</a></li>';
122 122
 
123
-        if ($direction ==='-') {
124
-            $jump_exists = (self::$t['page']-$m)>0;
123
+        if ($direction === '-') {
124
+            $jump_exists = (self::$t['page'] - $m) > 0;
125 125
         } else {
126
-            $jump_exists = (self::$t['page']+$m) <=self::$t['pages'];
126
+            $jump_exists = (self::$t['page'] + $m) <= self::$t['pages'];
127 127
         }
128 128
 
129 129
         if ($jump_exists) {
130
-            $html = $direction ==='-' ? $add . $html : $html . $add;
130
+            $html = $direction === '-' ? $add . $html : $html . $add;
131 131
         }
132 132
 
133 133
         return $jump_exists ? self::pagingJumps($html, ($m*10)) : $html;
@@ -139,13 +139,13 @@  discard block
 block discarded – undo
139 139
 
140 140
         $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT);
141 141
         foreach (self::$cols as $k => $v) {
142
-            if (isset($v[2]['sort'])&&$v[2]['sort'] ===false) {
142
+            if (isset($v[2]['sort']) && $v[2]['sort'] === false) {
143 143
                 continue;
144 144
             }
145 145
             if (empty($v)) {
146 146
                 $v = [null];
147 147
             } // fix for column requested as []
148
-            $selected = $by ===$k ? ' selected' : null;
148
+            $selected = $by === $k ? ' selected' : null;
149 149
             $opts[] = "<option value=\"{$k}\"{$selected}>{$v[0]}</option>";
150 150
         }
151 151
     }
@@ -155,10 +155,10 @@  discard block
 block discarded – undo
155 155
         $filter = filter_input(INPUT_GET, 'filter') ?: false;
156 156
         if ($filter) {
157 157
             $by = filter_input(INPUT_GET, 'filter-by', FILTER_VALIDATE_INT);
158
-            if ($by ===false||is_null($by)) {
158
+            if ($by === false || is_null($by)) {
159 159
                 $by = [];
160 160
                 foreach (self::$cols as $v) {
161
-                    if (isset($v[2]['sort'])&&$v[2]['sort'] ===false) {
161
+                    if (isset($v[2]['sort']) && $v[2]['sort'] === false) {
162 162
                         continue;
163 163
                     }
164 164
                     $by[] = 'IFNULL(' . $v[1] . ', "")';
@@ -168,7 +168,7 @@  discard block
 block discarded – undo
168 168
                 $by = self::$cols[$by][1];
169 169
             }
170 170
             $by = 'CONCAT(" ",' . $by . ', " ")';
171
-            if (self::config('FILTER_CASE_SENSITIVE') !==true) {
171
+            if (self::config('FILTER_CASE_SENSITIVE') !== true) {
172 172
                 $by .= ' COLLATE ' . self::config('DB_COLLATION_CI');
173 173
             }
174 174
             $filter = $by . ' LIKE ' . '"%' . $filter . '%"';
@@ -180,8 +180,7 @@  discard block
 block discarded – undo
180 180
     {
181 181
         if (($col = filter_input(INPUT_GET, 'col', FILTER_VALIDATE_INT))) {
182 182
             return isset(self::$cols[$col][2]['sort']) ?
183
-                    self::$cols[$col][2]['sort'] :
184
-                    self::$cols[$col][1];
183
+                    self::$cols[$col][2]['sort'] : self::$cols[$col][1];
185 184
         }
186 185
         return self::$t['order']['col'];
187 186
     }
@@ -190,8 +189,7 @@  discard block
 block discarded – undo
190 189
     {
191 190
         $reset = filter_has_var(INPUT_GET, 'col') ? 'asc' : null;
192 191
         return in_array(filter_input(INPUT_GET, 'ord'), ['asc', 'desc']) ?
193
-                filter_input(INPUT_GET, 'ord') :
194
-                ($reset ?: self::$t['order']['dir']);
192
+                filter_input(INPUT_GET, 'ord') : ($reset ?: self::$t['order']['dir']);
195 193
     }
196 194
 
197 195
     protected static function requestExport()
@@ -202,8 +200,7 @@  discard block
 block discarded – undo
202 200
 
203 201
     protected static function requestPage()
204 202
     {
205
-        return filter_has_var(INPUT_GET, 'pg')&&self::$export ==false ?
206
-                (int) filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) :
207
-                self::$t['page'];
203
+        return filter_has_var(INPUT_GET, 'pg') && self::$export == false ?
204
+                (int)filter_input(INPUT_GET, 'pg', FILTER_SANITIZE_NUMBER_INT) : self::$t['page'];
208 205
     }
209 206
 }
Please login to merge, or discard this patch.
table.php 1 patch
Spacing   +9 added lines, -12 removed lines patch added patch discarded remove patch
@@ -33,10 +33,8 @@  discard block
 block discarded – undo
33 33
         self::prepare(true);
34 34
         self::$t['order']['col'] = $orderBy;
35 35
         $dir = strtolower($orderDir);
36
-        self::$t['order']['dir'] = in_array($dir, ['asc', 'desc']) ? $dir :
37
-                die('Invalid orderDir(Asc/Desc): ' . $orderDir);
38
-        self::$t['paging'] = ($p = abs($paging)) > 10 ? $p :
39
-                die('Invalid paging(>10): ' . $paging);
36
+        self::$t['order']['dir'] = in_array($dir, ['asc', 'desc']) ? $dir : die('Invalid orderDir(Asc/Desc): ' . $orderDir);
37
+        self::$t['paging'] = ($p = abs($paging)) > 10 ? $p : die('Invalid paging(>10): ' . $paging);
40 38
     }
41 39
 
42 40
     /** #2. Execute (queries)
@@ -55,15 +53,15 @@  discard block
 block discarded – undo
55 53
 
56 54
         $filter = self::requestFilter();
57 55
         $order = [self::$t['order']['col'] => self::$t['order']['dir']];
58
-        $offset = (self::$t['page'] - 1) * self::$t['paging'];
56
+        $offset = (self::$t['page'] - 1)*self::$t['paging'];
59 57
         $limit = [$offset, self::$t['paging']];
60 58
         self::$t['q'] = self::q($q, $filter, $order, $limit, true);
61 59
 
62
-        $qAll = isset($qTotal) && ! $filter ? $qTotal : $q;
63
-        $orderAll = ! self::$export ? [] : $order;
60
+        $qAll = isset($qTotal) && !$filter ? $qTotal : $q;
61
+        $orderAll = !self::$export ? [] : $order;
64 62
         self::$t['qAll'] = self::q($qAll, $filter, $orderAll, 0, true);
65 63
 
66
-        $query = ! self::$export ? self::$t['q'] : self::$t['qAll'];
64
+        $query = !self::$export ? self::$t['q'] : self::$t['qAll'];
67 65
 
68 66
         try {
69 67
             self::$data = self::select($query);
@@ -81,7 +79,7 @@  discard block
 block discarded – undo
81 79
             ob_get_clean();
82 80
             $tableId = filter_input(INPUT_GET, 'table-id') ?: null;
83 81
             if ($tableId === self::$t['items'] . '-table') {
84
-                if ( ! self::$export) {
82
+                if (!self::$export) {
85 83
                     header('Content-Type: application/json');
86 84
                     $jsonArr = ['body' => self::jsonGetBodyData(),
87 85
                         'footer' => self::jsonGetFooterData()];
@@ -99,8 +97,7 @@  discard block
 block discarded – undo
99 97
     public static function prepare($setOrCheck = false)
100 98
     {
101 99
         //@see  http://php.net/manual/es/function.filter-input.php#77307
102
-        $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?:
103
-                filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
100
+        $uri = filter_input(INPUT_SERVER, 'REQUEST_URI', FILTER_SANITIZE_URL) ?: filter_var($_SERVER['REQUEST_URI'], FILTER_SANITIZE_URL);
104 101
 
105 102
         $extension = pathinfo(strtok($uri, '?'), PATHINFO_EXTENSION);
106 103
 
@@ -108,7 +105,7 @@  discard block
 block discarded – undo
108 105
         self::$pageExt = strtolower($extension);
109 106
 
110 107
         if (self::$helper_class::prepare(__METHOD__, $setOrCheck) !== true) {
111
-            if (self::$pageExt === 'json' && ! isset(self::$t['prepared'])) {
108
+            if (self::$pageExt === 'json' && !isset(self::$t['prepared'])) {
112 109
                 ob_start();
113 110
                 self::$t['prepared'] = true;
114 111
             }
Please login to merge, or discard this patch.
table_getter.php 1 patch
Spacing   +35 added lines, -44 removed lines patch added patch discarded remove patch
@@ -22,23 +22,22 @@  discard block
 block discarded – undo
22 22
         if (self::$cols) {
23 23
             $ths = [];
24 24
             $length = sizeof(self::$cols);
25
-            for ($i = 0; $i<$length; $i++) {
25
+            for ($i = 0; $i < $length; $i++) {
26 26
                 list($lbl, $col, $arg) = array_pad(self::$cols[$i], 3, null);
27 27
 
28 28
                 if (is_null($col)) {
29 29
                     $arg['sort'] = false;
30 30
                 }
31 31
 
32
-                $sortable = !isset($arg['sort'])||$arg['sort'] !==false;
32
+                $sortable = !isset($arg['sort']) || $arg['sort'] !== false;
33 33
 
34 34
                 $sort = $sortable ?
35
-                        (isset($arg['sort']) ? $arg['sort'] : $col) :
36
-                        null;
35
+                        (isset($arg['sort']) ? $arg['sort'] : $col) : null;
37 36
 
38
-                if (($del = isset($arg['type'])&&$arg['type'] =='delete')) {
37
+                if (($del = isset($arg['type']) && $arg['type'] == 'delete')) {
39 38
                     $sortable = false;
40
-                    if (!isset($arg['width'])&&
41
-                            false ===strpos($arg['width'], 'width:')
39
+                    if (!isset($arg['width']) &&
40
+                            false === strpos($arg['width'], 'width:')
42 41
                     ) {
43 42
                         $arg['width'] = '1%';
44 43
                     }
@@ -47,21 +46,19 @@  discard block
 block discarded – undo
47 46
                 if (isset($arg['width'])) { // Width attribute -> style
48 47
                     $width = 'width:' . $arg['width'] . ';';
49 48
                     $arg['style'] = isset($arg['style']) ?
50
-                            $width . $arg['style'] :
51
-                            $width;
49
+                            $width . $arg['style'] : $width;
52 50
                 }
53 51
 
54
-                $attr = array_diff_key((array) $arg, ['sort', 'type', 'width']);
52
+                $attr = array_diff_key((array)$arg, ['sort', 'type', 'width']);
55 53
 
56 54
                 $th = '<th' . self::attributes($attr) . '>';
57 55
                 if ($sortable) {
58 56
                     $th .= '<a onclick="table.Sort(' . $i . ',this);">';
59 57
                 }
60 58
                 if (!$del) {
61
-                    if ($sort ==self::$t['order']['col']) {
62
-                        $span = self::$t['order']['dir'] ==='desc' ?
63
-                                self::config('UTF8_DESC_SYMBOL') :
64
-                                self::config('UTF8_ASC_SYMBOL');
59
+                    if ($sort == self::$t['order']['col']) {
60
+                        $span = self::$t['order']['dir'] === 'desc' ?
61
+                                self::config('UTF8_DESC_SYMBOL') : self::config('UTF8_ASC_SYMBOL');
65 62
                     } else {
66 63
                         $span = "";
67 64
                     }
@@ -91,9 +88,8 @@  discard block
 block discarded – undo
91 88
     protected static function q($q, $cond = null, array $order = [], $limit = 0, $h = false)
92 89
     {
93 90
         //Condition: '' | '(HAVING|WHERE|AND) ' . $cond
94
-        $c = !empty($cond)&&!strpos($q, ($cl = !$h ? 'WHERE' : 'HAVING')) ?
95
-                (' ' . (!strpos($q, $cl) ? $cl : ' AND ') . ' ' . $cond ) :
96
-                '';
91
+        $c = !empty($cond) && !strpos($q, ($cl = !$h ? 'WHERE' : 'HAVING')) ?
92
+                (' ' . (!strpos($q, $cl) ? $cl : ' AND ') . ' ' . $cond) : '';
97 93
         //Order: '' | 'ORDER BY ' . array_keys($order)[0] . ' ' . $order[0]
98 94
         $o = !empty($order) ?
99 95
                 ' ORDER BY ' . implode(', ',
@@ -104,8 +100,7 @@  discard block
 block discarded – undo
104 100
                 '';
105 101
         //Limit: '' | ' LIMIT ' . '(20, 40|20)'
106 102
         $l = !empty($limit) ?
107
-                (' LIMIT ' . (is_array($limit) ? implode(', ', $limit) : $limit)) :
108
-                '';
103
+                (' LIMIT ' . (is_array($limit) ? implode(', ', $limit) : $limit)) : '';
109 104
 
110 105
         return $q . $c . $o . $l;
111 106
     }
@@ -113,8 +108,7 @@  discard block
 block discarded – undo
113 108
     protected static function exportData()
114 109
     {
115 110
         $data = self::$exportDataAsDisplayed ?
116
-                self::$data :
117
-                self::select(self::$t['q']);
111
+                self::$data : self::select(self::$t['q']);
118 112
         $fnReplace = [];
119 113
         $fnReplace[':app'] = self::$app;
120 114
         $fnReplace[':items'] = self::$t['items'];
@@ -124,14 +118,14 @@  discard block
 block discarded – undo
124 118
         $outFilename = strtr(self::config('EXPORT_FILE_NAME'), $fnReplace);
125 119
         $outColumns = $outHeader = [];
126 120
         foreach (self::$cols as $c) {
127
-            if (isset($c[2]['sort'])&&$c[2]['sort'] ===false) {
121
+            if (isset($c[2]['sort']) && $c[2]['sort'] === false) {
128 122
                 continue;
129 123
             }
130 124
             $outColumns[] = $c[1];
131 125
             $outHeader[] = $c[0];
132 126
         }
133 127
         $eData = [$outHeader];
134
-        if (count($data)>0) {
128
+        if (count($data) > 0) {
135 129
             foreach ($data as $row) {
136 130
                 $rowData = [];
137 131
                 foreach ($row as $dbName => $value) {
@@ -157,11 +151,10 @@  discard block
 block discarded – undo
157 151
                 header('Content-Disposition:attachment; filename=' .
158 152
                         $outFilename . '.csv');
159 153
                 
160
-                if(($output = fopen('php://output', 'w'))){
154
+                if (($output = fopen('php://output', 'w'))) {
161 155
                     foreach ($eData as $v) {
162
-                        self::$export ==='CSV' ?
163
-                        fputcsv($output, $v) :
164
-                        fputs($output, implode("\t", array_map($escape, $v)) . "\r\n");
156
+                        self::$export === 'CSV' ?
157
+                        fputcsv($output, $v) : fputs($output, implode("\t", array_map($escape, $v)) . "\r\n");
165 158
                     }
166 159
                     fclose($output);
167 160
                 }
@@ -175,7 +168,7 @@  discard block
 block discarded – undo
175 168
         foreach (self::$cols as $c) {
176 169
             $outColumns[] = isset($c[1]) ? $c[1] : null;
177 170
         }
178
-        if ((self::$t['rows'] = count(self::$data))>0) {
171
+        if ((self::$t['rows'] = count(self::$data)) > 0) {
179 172
             foreach (self::$data as $row) {
180 173
                 $rowData = [];
181 174
                 foreach ($outColumns as $dbName) {
@@ -194,9 +187,9 @@  discard block
 block discarded – undo
194 187
     protected static function jsonGetFooterData()
195 188
     {
196 189
         $jsonArrFooter = [];
197
-        if (count(self::$data)>0) {
190
+        if (count(self::$data) > 0) {
198 191
             $pageNo = self::$t['page'];
199
-            if ($pageNo ===1&&count(self::$data)<self::$t['paging']) {
192
+            if ($pageNo === 1 && count(self::$data) < self::$t['paging']) {
200 193
                 //Skips total count query
201 194
                 self::$t['rows'] = count(self::$data);
202 195
             } else {
@@ -207,15 +200,14 @@  discard block
 block discarded – undo
207 200
 
208 201
             $v = [];
209 202
 
210
-            $v['from'] = ($pageNo-1)*self::$t['paging']+1;
211
-            $v['upto'] = ($pageNo*self::$t['paging']<self::$t['rows']) ?
212
-                    $pageNo*self::$t['paging'] :
213
-                    self::$t['rows'];
203
+            $v['from'] = ($pageNo - 1)*self::$t['paging'] + 1;
204
+            $v['upto'] = ($pageNo*self::$t['paging'] < self::$t['rows']) ?
205
+                    $pageNo*self::$t['paging'] : self::$t['rows'];
214 206
 
215 207
             $v["total"] = self::$t['rows'];
216 208
             $v["items"] = self::$t['items'];
217 209
 
218
-            if (self::$exportActive ===true) {
210
+            if (self::$exportActive === true) {
219 211
                 $url = strtok(self::$t['slug'], "?&") . ".json?table=" .
220 212
                         self::$t['items'] . "&export=";
221 213
                 $v["export"] = ["url" => $url, "types" => self::config('SAVES')];
@@ -265,10 +257,10 @@  discard block
 block discarded – undo
265 257
     private static function rows($for)
266 258
     {
267 259
         $trs = '';
268
-        if ($for ==='body') {
260
+        if ($for === 'body') {
269 261
             foreach (self::jsonGetBodyData() as $r) {
270
-                if (isset($r[0][1], $r[0][1]['class'])&&
271
-                        $r[0][1]['class'] ==='no-results'
262
+                if (isset($r[0][1], $r[0][1]['class']) &&
263
+                        $r[0][1]['class'] === 'no-results'
272 264
                 ) {
273 265
                     $trs .= '<tr><td' . self::attributes($r[0][1]) . '>'
274 266
                             . $r[0][0] . '</td></tr>';
@@ -277,8 +269,8 @@  discard block
 block discarded – undo
277 269
                             . '</td></tr>';
278 270
                 }
279 271
             }
280
-        } else if ($for ==='footer') {
281
-            if (self::$t['rows']>0) {
272
+        } else if ($for === 'footer') {
273
+            if (self::$t['rows'] > 0) {
282 274
                 $ftr = self::jsonGetFooterData()[0][0];
283 275
                 $trs .= '<tr><td' . self::attributes($ftr[1]) . '>'
284 276
                         . $ftr[0] . '</td></tr>';
@@ -300,13 +292,12 @@  discard block
 block discarded – undo
300 292
 
301 293
     static function select(string $expression, array $bindings = [])
302 294
     {
303
-        if (is_object(static::$select)&&(static::$select instanceof Closure)) {
295
+        if (is_object(static::$select) && (static::$select instanceof Closure)) {
304 296
             $select = static::$select;
305 297
             $res = $select($expression, $bindings);
306 298
             //if result is single cell value ($res[0]->value), return the value
307
-            return (count($res) ===1&&count((array) $res[0]) ===1) ?
308
-                    reset($res[0]) :
309
-                    $res;
299
+            return (count($res) === 1 && count((array)$res[0]) === 1) ?
300
+                    reset($res[0]) : $res;
310 301
         } else {
311 302
             die('ERROR: table::$select is not a valid closure. '
312 303
                     . __METHOD__ . '() #' . __LINE__);
Please login to merge, or discard this patch.