Completed
Push — master ( bc825a...1aba9a )
by William
06:03
created

OrderSearchComponent::getSearchConditions()   A

Complexity

Conditions 6
Paths 6

Size

Total Lines 21
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 11
CRAP Score 6

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 6
eloc 10
nc 6
nop 1
dl 0
loc 21
ccs 11
cts 11
cp 1
crap 6
rs 9.2222
c 1
b 0
f 0
1
<?php
2
3
/* vim: set expandtab sw=4 ts=4 sts=4: */
4
/**
5
 * Order and search component handling generation of ordering and
6
 * searching conditions in loading data tables.
7
 *
8
 * phpMyAdmin Error reporting server
9
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
10
 *
11
 * Licensed under The MIT License
12
 * For full copyright and license information, please see the LICENSE.txt
13
 * Redistributions of files must retain the above copyright notice.
14
 *
15
 * @copyright Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
16
 * @license   https://opensource.org/licenses/mit-license.php MIT License
17
 *
18
 * @see      https://www.phpmyadmin.net/
19
 */
20
21
namespace App\Controller\Component;
22
23
use Cake\Controller\Component;
24
25
/**
26
 * Github api component handling comunication with github.
27
 */
28
class OrderSearchComponent extends Component
29
{
30
    /**
31
     * Indexes are +1'ed because first column is of checkboxes
32
     * and hence it should be ingnored.
33
     *
34
     * @param string[] $aColumns The columns
35
     *
36
     * @return array
37
     */
38 2
    public function getSearchConditions($aColumns)
39
    {
40 2
        $searchConditions = ['OR' => []];
41 2
        $keys = array_keys($aColumns);
42
43 2
        if ($this->request->query('sSearch') != '') {
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

43
        if (/** @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...
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

43
        if (/** @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...
44 1
            for ($i = 0; $i < count($aColumns); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
45 1
                if ($this->request->query('bSearchable_' . ($i + 1)) == 'true') {
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

45
                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...
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

45
                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...
46 1
                    $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . $this->request->query('sSearch') . '%'];
0 ignored issues
show
Bug introduced by
Are you sure $this->request->query('sSearch') of type array|null|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

46
                    $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . /** @scrutinizer ignore-type */ $this->request->query('sSearch') . '%'];
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
                    $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . /** @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...
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
                    $searchConditions['OR'][] = [$aColumns[$keys[$i]] . ' LIKE' => '%' . /** @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...
47
                }
48
            }
49
        }
50
51
        /* Individual column filtering */
52 2
        for ($i = 0; $i < count($aColumns); ++$i) {
0 ignored issues
show
Performance Best Practice introduced by
It seems like you are calling the size function count() as part of the test condition. You might want to compute the size beforehand, and not on each iteration.

If the size of the collection does not change during the iteration, it is generally a good practice to compute it beforehand, and not on each iteration:

for ($i=0; $i<count($array); $i++) { // calls count() on each iteration
}

// Better
for ($i=0, $c=count($array); $i<$c; $i++) { // calls count() just once
}
Loading history...
53 2
            if ($this->request->query('sSearch_' . ($i + 1)) != '') {
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

53
            if (/** @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...
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

53
            if (/** @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...
54 1
                $searchConditions[] = [$aColumns[$keys[$i]] . ' LIKE' => $this->request->query('sSearch_' . ($i + 1))];
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

54
                $searchConditions[] = [$aColumns[$keys[$i]] . ' LIKE' => /** @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...
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

54
                $searchConditions[] = [$aColumns[$keys[$i]] . ' LIKE' => /** @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...
55
            }
56
        }
57
58 2
        return $searchConditions;
59
    }
60
61
    /**
62
     * @param string[] $aColumns The columns
63
     *
64
     * @return array
65
     */
66 2
    public function getOrder($aColumns)
67
    {
68 2
        if ($this->request->query('iSortCol_0') != null) {
0 ignored issues
show
Bug introduced by
It seems like you are loosely comparing $this->request->query('iSortCol_0') of type array|null|string against null; this is ambiguous if the string can be empty. Consider using a strict comparison !== 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

68
        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

68
        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...
69 1
            $order = [];
70
            //Seems like we need to sort with only one column each time, so no need to loop
71 1
            $sort_column_index = intval($this->request->query('iSortCol_0'));
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

71
            $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...
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

71
            $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...
72
73 1
            $keys = array_keys($aColumns);
74
75 1
            if ($sort_column_index > 0
76 1
                && $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

76
                && /** @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

76
                && /** @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...
77
            ) {
78
                $order[$aColumns[$keys[$sort_column_index - 1]]] = $this->request->query('sSortDir_0');
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

78
                $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...
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

78
                $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...
79
            }
80
81 1
            return $order;
82
        }
83
84 2
        return null;
85
    }
86
}
87