Completed
Push — master ( 740d41...a3b506 )
by Michal
07:10 queued 16s
created

OrderSearchComponent   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 56
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 56
ccs 22
cts 22
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
B getSearchConditions() 0 22 6
A getOrder() 0 18 4
1
<?php
2
/* vim: set noexpandtab sw=2 ts=2 sts=2: */
3
namespace App\Controller\Component;
4
5
use Cake\Controller\Component;
6
use Cake\Routing\Router;
7
/**
8
 * Order and search component handling generation of ordering and
9
 * searching conditions in loading data tables
10
 *
11
 * phpMyAdmin Error reporting server
12
 * Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
13
 *
14
 * Licensed under The MIT License
15
 * For full copyright and license information, please see the LICENSE.txt
16
 * Redistributions of files must retain the above copyright notice.
17
 *
18
 * @copyright     Copyright (c) phpMyAdmin project (https://www.phpmyadmin.net/)
19
 * @package       Server.Controller.Component
20
 * @link          https://www.phpmyadmin.net/
21
 * @license       https://opensource.org/licenses/mit-license.php MIT License
22
 */
23
24
25
/**
26
 * Github api component handling comunication with github
27
 *
28
 * @package       Server.Controller.Component
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
	 * @param string[] $aColumns
36
	 *
37
	 * @return array
38
	 */
39 1
	public function getSearchConditions($aColumns) {
40 1
		$searchConditions = array('OR' => array());
41 1
		$keys = array_keys($aColumns);
42
43 1
		if ( $this->request->query('sSearch') != "" ) {
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") {
46 1
					$searchConditions['OR'][] = array($aColumns[$keys[$i]] . " LIKE" =>
47 1
							"%" . $this->request->query('sSearch') . "%");
48
				}
49
			}
50
		}
51
52
		/* Individual column filtering */
53 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...
54 1
			if ($this->request->query('sSearch_' . ($i+1)) != '') {
55 1
				$searchConditions[] = array($aColumns[$keys[$i]] . " LIKE" =>
56 1
						$this->request->query('sSearch_' . ($i+1)));
57
			}
58
		}
59 1
		return $searchConditions;
60
	}
61
62
	/**
63
	 * @param string[] $aColumns
64
	 *
65
	 * @return array
66
	 */
67 1
	public function getOrder($aColumns) {
68 1
		if ( $this->request->query('iSortCol_0') != null ) {
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'));
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"
77
			) {
78
				$order[$aColumns[$keys[$sort_column_index - 1]]] = $this->request->query('sSortDir_0');
79
			}
80 1
			return $order;
81
		} else {
82 1
			return null;
83
		}
84
	}
85
}