@@ -25,7 +25,7 @@ |
||
25 | 25 | { |
26 | 26 | $key = (strpos($prop, "on") !== 0) ? Inflector::underscore($prop) : $prop; |
27 | 27 | |
28 | - if ($value instanceof Optionable){ |
|
28 | + if ($value instanceof Optionable) { |
|
29 | 29 | $value = $value->toOptions(); |
30 | 30 | } elseif (is_array($value)) { |
31 | 31 | foreach ($value as $k => $v) { |
@@ -13,82 +13,82 @@ |
||
13 | 13 | return [ |
14 | 14 | [ |
15 | 15 | ['condition' => "and", 'rules' => [ |
16 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], |
|
17 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_equal', 'value' => 'bruce'] |
|
16 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], |
|
17 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_equal', 'value' => 'bruce'] |
|
18 | 18 | ]], |
19 | 19 | ['(name = :p0 and name <> :p1)', [':p0' => 'joe', ':p1' => 'bruce']] |
20 | 20 | ], |
21 | 21 | [ |
22 | 22 | ['condition' => "and", 'rules' => [ |
23 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'in', 'value' => [1,2,3]], |
|
24 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'not_in', 'value' => [4,5]] |
|
23 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'in', 'value' => [1, 2, 3]], |
|
24 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'not_in', 'value' => [4, 5]] |
|
25 | 25 | ]], |
26 | 26 | ['(id IN (:p0, :p1, :p2) and id NOT IN (:p3, :p4))', [':p0'=>1, ':p1'=>2, ':p2'=>3, ':p3'=>4, ':p4'=>5]] |
27 | 27 | ], |
28 | 28 | [ |
29 | 29 | ['condition' => "and", 'rules' => [ |
30 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'less', 'value' => 100], |
|
31 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'less_or_equal', 'value' => 50], |
|
30 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'less', 'value' => 100], |
|
31 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'less_or_equal', 'value' => 50], |
|
32 | 32 | ]], |
33 | 33 | ['(id < :p0 and id <= :p1)', [':p0'=>100, ':p1'=>50]] |
34 | 34 | ], |
35 | 35 | [ |
36 | 36 | ['condition' => "and", 'rules' => [ |
37 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'greater', 'value' => 10], |
|
38 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'greater_or_equal', 'value' => 20], |
|
37 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'greater', 'value' => 10], |
|
38 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'greater_or_equal', 'value' => 20], |
|
39 | 39 | ]], |
40 | 40 | ['(id > :p0 and id >= :p1)', [':p0'=>10, ':p1'=>20]] |
41 | 41 | ], |
42 | 42 | [ |
43 | 43 | ['condition' => "and", 'rules' => [ |
44 | - [ 'field' => 'date', 'type' => 'date', 'operator' => 'between', 'value' => ['2015-01-01','2015-01-30']], |
|
44 | + ['field' => 'date', 'type' => 'date', 'operator' => 'between', 'value' => ['2015-01-01', '2015-01-30']], |
|
45 | 45 | ]], |
46 | 46 | ['(date BETWEEN :p0 AND :p1)', [':p0'=>'2015-01-01', ':p1'=>'2015-01-30']] |
47 | 47 | ], |
48 | 48 | [ |
49 | 49 | ['condition' => "and", 'rules' => [ |
50 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], |
|
51 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], |
|
50 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'joe'], |
|
51 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_begins_with', 'value' => 'bruce'], |
|
52 | 52 | ]], |
53 | 53 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'joe%', ':p1'=> 'bruce%']] |
54 | 54 | ], |
55 | 55 | [ |
56 | 56 | ['condition' => "and", 'rules' => [ |
57 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], |
|
58 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], |
|
57 | + ['field' => 'name', 'type' => 'string', 'operator' => 'contains', 'value' => 'thomas'], |
|
58 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_contains', 'value' => 'paul'], |
|
59 | 59 | ]], |
60 | 60 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%thomas%', ':p1'=> '%paul%']] |
61 | 61 | ], |
62 | 62 | [ |
63 | 63 | ['condition' => "and", 'rules' => [ |
64 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], |
|
65 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], |
|
64 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'brian'], |
|
65 | + ['field' => 'name', 'type' => 'string', 'operator' => 'not_ends_with', 'value' => 'david'], |
|
66 | 66 | ]], |
67 | 67 | ['(name LIKE :p0 and name NOT LIKE :p1)', [':p0'=>'%brian', ':p1'=> '%david']] |
68 | 68 | ], |
69 | 69 | [ |
70 | 70 | ['condition' => "or", 'rules' => [ |
71 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], |
|
72 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], |
|
73 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_null'], |
|
74 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], |
|
71 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_empty'], |
|
72 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_empty'], |
|
73 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_null'], |
|
74 | + ['field' => 'name', 'type' => 'string', 'operator' => 'is_not_null'], |
|
75 | 75 | ]], |
76 | 76 | ['(name = "" or name <> "" or name IS NULL or name IS NOT NULL)', []] |
77 | 77 | ], |
78 | 78 | [ |
79 | 79 | ['condition' => "and", 'rules' => [ |
80 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], |
|
81 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], |
|
80 | + ['field' => 'name', 'type' => 'string', 'operator' => 'begins_with', 'value' => 'kurt'], |
|
81 | + ['field' => 'name', 'type' => 'string', 'operator' => 'ends_with', 'value' => 'cobain'], |
|
82 | 82 | ['condition' => 'or', 'rules'=>[ |
83 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], |
|
84 | - [ 'field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], |
|
83 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'joe'], |
|
84 | + ['field' => 'name', 'type' => 'string', 'operator' => 'equal', 'value' => 'paul'], |
|
85 | 85 | ['condition' => 'and', 'rules'=>[ |
86 | - [ 'field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], |
|
86 | + ['field' => 'id', 'type' => 'integer', 'operator' => 'equal', 'value' => 10], |
|
87 | 87 | ]] |
88 | 88 | ]] |
89 | 89 | ]], |
90 | 90 | ['(name LIKE :p0 and name LIKE :p1 and (name = :p2 or name = :p3 or (id = :p4)))', [ |
91 | - ':p0'=>'kurt%',':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 |
|
91 | + ':p0'=>'kurt%', ':p1' =>'%cobain', ':p2' => 'joe', ':p3' => 'paul', ':p4' => 10 |
|
92 | 92 | ]] |
93 | 93 | ] |
94 | 94 |
@@ -191,10 +191,10 @@ |
||
191 | 191 | } |
192 | 192 | |
193 | 193 | /** |
194 | - * |
|
195 | - * @param array $currentParams |
|
196 | - * @return \leandrogehlen\querybuilder\Translator |
|
197 | - */ |
|
194 | + * |
|
195 | + * @param array $currentParams |
|
196 | + * @return \leandrogehlen\querybuilder\Translator |
|
197 | + */ |
|
198 | 198 | public function setCurrentParams($currentParams) { |
199 | 199 | $this->currentParams = $currentParams; |
200 | 200 | } |
@@ -51,7 +51,7 @@ discard block |
||
51 | 51 | */ |
52 | 52 | public function __construct($data, $config = []) |
53 | 53 | { |
54 | - if(isset($config['currentParams'])){ |
|
54 | + if (isset($config['currentParams'])) { |
|
55 | 55 | $this->setCurrentParams($config['currentParams']); |
56 | 56 | |
57 | 57 | } |
@@ -67,19 +67,19 @@ discard block |
||
67 | 67 | $this->_operators = [ |
68 | 68 | 'equal' => '= ?', |
69 | 69 | 'not_equal' => '<> ?', |
70 | - 'in' => ['op' => 'IN (?)', 'list' => true, 'sep' => ', ' ], |
|
70 | + 'in' => ['op' => 'IN (?)', 'list' => true, 'sep' => ', '], |
|
71 | 71 | 'not_in' => ['op' => 'NOT IN (?)', 'list' => true, 'sep' => ', '], |
72 | 72 | 'less' => '< ?', |
73 | 73 | 'less_or_equal' => '<= ?', |
74 | 74 | 'greater' => '> ?', |
75 | 75 | 'greater_or_equal' => '>= ?', |
76 | - 'between' => ['op' => 'BETWEEN ?', 'list' => true, 'sep' => ' AND '], |
|
77 | - 'begins_with' => ['op' => 'LIKE ?', 'fn' => function($value){ return "$value%"; } ], |
|
78 | - 'not_begins_with' => ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "$value%"; } ], |
|
79 | - 'contains' => ['op' => 'LIKE ?', 'fn' => function($value){ return "%$value%"; } ], |
|
80 | - 'not_contains' => ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value%"; } ], |
|
81 | - 'ends_with' => ['op' => 'LIKE ?', 'fn' => function($value){ return "%$value"; } ], |
|
82 | - 'not_ends_with' => ['op' => 'NOT LIKE ?', 'fn' => function($value){ return "%$value"; } ], |
|
76 | + 'between' => ['op' => 'BETWEEN ?', 'list' => true, 'sep' => ' AND '], |
|
77 | + 'begins_with' => ['op' => 'LIKE ?', 'fn' => function($value) { return "$value%"; }], |
|
78 | + 'not_begins_with' => ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "$value%"; }], |
|
79 | + 'contains' => ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value%"; }], |
|
80 | + 'not_contains' => ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value%"; }], |
|
81 | + 'ends_with' => ['op' => 'LIKE ?', 'fn' => function($value) { return "%$value"; }], |
|
82 | + 'not_ends_with' => ['op' => 'NOT LIKE ?', 'fn' => function($value) { return "%$value"; }], |
|
83 | 83 | 'is_empty' => '= ""', |
84 | 84 | 'is_not_empty' => '<> ""', |
85 | 85 | 'is_null' => 'IS NULL', |
@@ -105,7 +105,7 @@ discard block |
||
105 | 105 | } else { |
106 | 106 | $op = ArrayHelper::getValue($pattern, 'op'); |
107 | 107 | $list = ArrayHelper::getValue($pattern, 'list'); |
108 | - if ($list){ |
|
108 | + if ($list) { |
|
109 | 109 | $sep = ArrayHelper::getValue($pattern, 'sep'); |
110 | 110 | $replacement = implode($sep, $keys); |
111 | 111 | } else { |
@@ -117,7 +117,7 @@ discard block |
||
117 | 117 | } |
118 | 118 | |
119 | 119 | $this->_params = array_merge($this->_params, $params); |
120 | - return $field . " " . ($replacement ? str_replace("?", $replacement, $pattern) : $pattern); |
|
120 | + return $field." ".($replacement ? str_replace("?", $replacement, $pattern) : $pattern); |
|
121 | 121 | } |
122 | 122 | |
123 | 123 | /** |
@@ -131,7 +131,7 @@ discard block |
||
131 | 131 | } |
132 | 132 | |
133 | 133 | $where = []; |
134 | - $condition = " " . $data['condition'] . " "; |
|
134 | + $condition = " ".$data['condition']." "; |
|
135 | 135 | |
136 | 136 | foreach ($data['rules'] as $rule) { |
137 | 137 | if (isset($rule['condition'])) { |
@@ -155,7 +155,7 @@ discard block |
||
155 | 155 | $where[] = $this->encodeRule($field, $operator, $params); |
156 | 156 | } |
157 | 157 | } |
158 | - return "(" . implode($condition, $where) . ")"; |
|
158 | + return "(".implode($condition, $where).")"; |
|
159 | 159 | } |
160 | 160 | |
161 | 161 | /** |
@@ -180,11 +180,11 @@ discard block |
||
180 | 180 | * Get a param name that should not conflict with any params already set |
181 | 181 | * @return string |
182 | 182 | */ |
183 | - private function getNewParamName(){ |
|
183 | + private function getNewParamName() { |
|
184 | 184 | $paramPrefix = 'p'; |
185 | - if(!empty($this->currentParams) && $this->paramsCount < count($this->currentParams) ){ |
|
186 | - $this->paramsCount = count($this->currentParams) +1; |
|
187 | - }else{ |
|
185 | + if (!empty($this->currentParams) && $this->paramsCount < count($this->currentParams)) { |
|
186 | + $this->paramsCount = count($this->currentParams) + 1; |
|
187 | + } else { |
|
188 | 188 | $this->paramsCount = $this->paramsCount + 1; |
189 | 189 | } |
190 | 190 | return $paramPrefix.$this->paramsCount; |
@@ -184,7 +184,7 @@ |
||
184 | 184 | $paramPrefix = 'p'; |
185 | 185 | if(!empty($this->currentParams) && $this->paramsCount < count($this->currentParams) ){ |
186 | 186 | $this->paramsCount = count($this->currentParams) +1; |
187 | - }else{ |
|
187 | + } else{ |
|
188 | 188 | $this->paramsCount = $this->paramsCount + 1; |
189 | 189 | } |
190 | 190 | return $paramPrefix.$this->paramsCount; |
@@ -5,12 +5,12 @@ |
||
5 | 5 | |
6 | 6 | define('YII_ENABLE_ERROR_HANDLER', false); |
7 | 7 | define('YII_DEBUG', true); |
8 | -$_SERVER['SCRIPT_NAME'] = '/' . __DIR__; |
|
8 | +$_SERVER['SCRIPT_NAME'] = '/'.__DIR__; |
|
9 | 9 | $_SERVER['SCRIPT_FILENAME'] = __FILE__; |
10 | 10 | |
11 | 11 | // require composer autoloader if available |
12 | -$vendor = __DIR__ . '/../../vendor'; |
|
12 | +$vendor = __DIR__.'/../../vendor'; |
|
13 | 13 | |
14 | -require_once($vendor . '/autoload.php'); |
|
15 | -require_once($vendor . '/yiisoft/yii2/Yii.php'); |
|
16 | -require_once(__DIR__ . '/TestCase.php'); |
|
14 | +require_once($vendor.'/autoload.php'); |
|
15 | +require_once($vendor.'/yiisoft/yii2/Yii.php'); |
|
16 | +require_once(__DIR__.'/TestCase.php'); |
@@ -17,14 +17,14 @@ discard block |
||
17 | 17 | */ |
18 | 18 | public static function setUpBeforeClass() |
19 | 19 | { |
20 | - $vendorDir = __DIR__ . '/../../vendor'; |
|
21 | - $vendorAutoload = $vendorDir . '/autoload.php'; |
|
20 | + $vendorDir = __DIR__.'/../../vendor'; |
|
21 | + $vendorAutoload = $vendorDir.'/autoload.php'; |
|
22 | 22 | if (file_exists($vendorAutoload)) { |
23 | 23 | require_once($vendorAutoload); |
24 | 24 | } else { |
25 | 25 | throw new NotSupportedException("Vendor autoload file '{$vendorAutoload}' is missing."); |
26 | 26 | } |
27 | - require_once($vendorDir . '/yiisoft/yii2/Yii.php'); |
|
27 | + require_once($vendorDir.'/yiisoft/yii2/Yii.php'); |
|
28 | 28 | Yii::setAlias('@vendor', $vendorDir); |
29 | 29 | } |
30 | 30 | |
@@ -37,7 +37,7 @@ discard block |
||
37 | 37 | 'id' => 'querybuilder-test', |
38 | 38 | 'basePath' => __DIR__, |
39 | 39 | ]; |
40 | - $config['vendorPath'] = dirname(dirname(__DIR__)) . '/vendor'; |
|
40 | + $config['vendorPath'] = dirname(dirname(__DIR__)).'/vendor'; |
|
41 | 41 | new \yii\console\Application($config); |
42 | 42 | } |
43 | 43 |