Completed
Push — master ( 07e3a8...9561cd )
by William
16:58 queued 14:23
created

OrderSearchComponent::getOrder()   A

Complexity

Conditions 4
Paths 3

Size

Total Lines 19
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4.016

Importance

Changes 2
Bugs 1 Features 0
Metric Value
cc 4
eloc 9
nc 3
nop 1
dl 0
loc 19
ccs 9
cts 10
cp 0.9
crap 4.016
rs 9.9666
c 2
b 1
f 0
1
<?php
2
3
/**
4
 * Order and search component handling generation of ordering and
5
 * searching conditions in loading data tables.
6
 *
7
 * phpMyAdmin Error reporting server
8
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
9
 *
10
 * Licensed under The MIT License
11
 * For full copyright and license information, please see the LICENSE.txt
12
 * Redistributions of files must retain the above copyright notice.
13
 *
14
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
15
 * @license   https://opensource.org/licenses/mit-license.php MIT License
16
 *
17
 * @see      https://www.phpmyadmin.net/
18
 */
19
20
namespace App\Controller\Component;
21
22
use Cake\Controller\Component;
23
use function array_keys;
24
use function count;
25
use function intval;
26
27
/**
28
 * Github api component handling comunication with github.
29
 */
30
class OrderSearchComponent extends Component
31
{
32
    /**
33
     * Indexes are +1'ed because first column is of checkboxes
34
     * and hence it should be ingnored.
35
     *
36
     * @param string[] $aColumns The columns
37
     *
38
     * @return array
39
     */
40 8
    public function getSearchConditions(array $aColumns): array
41
    {
42 8
        $searchConditions = ['OR' => []];
43 8
        $keys = array_keys($aColumns);
44 8
        $columnsCount = count($aColumns);
45
46 8
        $sSearch = $this->request->query('sSearch');
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

46
        $sSearch = /** @scrutinizer ignore-deprecated */ $this->request->query('sSearch');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

46
        $sSearch = /** @scrutinizer ignore-deprecated */ $this->request->query('sSearch');

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
47 8
        if ($sSearch !== '' && $sSearch !== null) {
48 4
            for ($i = 0; $i < $columnsCount; ++$i) {
49 4
                if ($this->request->query('bSearchable_' . ($i + 1)) !== 'true') {
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

49
                if (/** @scrutinizer ignore-deprecated */ $this->request->query('bSearchable_' . ($i + 1)) !== 'true') {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

49
                if (/** @scrutinizer ignore-deprecated */ $this->request->query('bSearchable_' . ($i + 1)) !== 'true') {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
50 4
                    continue;
51
                }
52
53 4
                $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . $sSearch . '%'];
0 ignored issues
show
Bug introduced by
Are you sure $sSearch of type array|string can be used in concatenation? ( Ignorable by Annotation )

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

53
                $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . /** @scrutinizer ignore-type */ $sSearch . '%'];
Loading history...
54
            }
55
        }
56
57
        /* Individual column filtering */
58 8
        for ($i = 0; $i < $columnsCount; ++$i) {
59 8
            $searchTerm = $this->request->query('sSearch_' . ($i + 1));
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

59
            $searchTerm = /** @scrutinizer ignore-deprecated */ $this->request->query('sSearch_' . ($i + 1));

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

59
            $searchTerm = /** @scrutinizer ignore-deprecated */ $this->request->query('sSearch_' . ($i + 1));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
60 8
            if ($searchTerm === '' || $searchTerm === null) {
61 8
                continue;
62
            }
63
64 4
            $searchConditions[] = [$aColumns[$keys[$i]] . ' LIKE' => $searchTerm];
65
        }
66
67 8
        return $searchConditions;
68
    }
69
70
    /**
71
     * @param string[] $aColumns The columns
72
     *
73
     * @return array|null
74
     */
75 8
    public function getOrder(array $aColumns): ?array
76
    {
77 8
        if ($this->request->query('iSortCol_0') !== null) {
0 ignored issues
show
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

77
        if (/** @scrutinizer ignore-deprecated */ $this->request->query('iSortCol_0') !== null) {

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

77
        if (/** @scrutinizer ignore-deprecated */ $this->request->query('iSortCol_0') !== null) {

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
78 4
            $order = [];
79
            //Seems like we need to sort with only one column each time, so no need to loop
80 4
            $sort_column_index = intval($this->request->query('iSortCol_0'));
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

80
            $sort_column_index = intval(/** @scrutinizer ignore-deprecated */ $this->request->query('iSortCol_0'));

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

80
            $sort_column_index = intval(/** @scrutinizer ignore-deprecated */ $this->request->query('iSortCol_0'));

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
81
82 4
            $keys = array_keys($aColumns);
83
84 4
            if ($sort_column_index > 0
85 4
                && $this->request->query('bSortable_' . $sort_column_index) === 'true'
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

85
                && /** @scrutinizer ignore-deprecated */ $this->request->query('bSortable_' . $sort_column_index) === 'true'

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

85
                && /** @scrutinizer ignore-deprecated */ $this->request->query('bSortable_' . $sort_column_index) === 'true'

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
86
            ) {
87
                $order[$aColumns[$keys[$sort_column_index - 1]]] = $this->request->query('sSortDir_0');
0 ignored issues
show
Deprecated Code introduced by
The property Cake\Controller\Component::$request has been deprecated: 3.4.0 Storing references to the request is deprecated. Use Component::getController() or callback $event->getSubject() to access the controller & request instead. ( Ignorable by Annotation )

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

87
                $order[$aColumns[$keys[$sort_column_index - 1]]] = /** @scrutinizer ignore-deprecated */ $this->request->query('sSortDir_0');

This property has been deprecated. The supplier of the class has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the property will be removed from the class and what other property to use instead.

Loading history...
Deprecated Code introduced by
The function Cake\Http\ServerRequest::query() has been deprecated: 3.4.0 Use getQuery() or the PSR-7 getQueryParams() and withQueryParams() methods instead. ( Ignorable by Annotation )

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

87
                $order[$aColumns[$keys[$sort_column_index - 1]]] = /** @scrutinizer ignore-deprecated */ $this->request->query('sSortDir_0');

This function has been deprecated. The supplier of the function has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the function will be removed and what other function to use instead.

Loading history...
88
            }
89
90 4
            return $order;
91
        }
92
93 8
        return null;
94
    }
95
}
96