@@ -34,8 +34,9 @@ |
||
34 | 34 | */ |
35 | 35 | protected function getExplainSyntax() |
36 | 36 | { |
37 | - if ( $this->queryStructure->getElement( QueryStructure::EXPLAIN ) ) |
|
38 | - return 'EXPLAIN'; |
|
37 | + if ( $this->queryStructure->getElement( QueryStructure::EXPLAIN ) ) { |
|
38 | + return 'EXPLAIN'; |
|
39 | + } |
|
39 | 40 | |
40 | 41 | return ''; |
41 | 42 | } |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @return $this |
27 | 27 | * @throws QueryException |
28 | 28 | */ |
29 | - public function orderBy( $column, array $allowedColumns = [] ) |
|
29 | + public function orderBy( $column, array $allowedColumns = [ ] ) |
|
30 | 30 | { |
31 | 31 | if ( !$this->validateColumn( $column, $allowedColumns ) ) |
32 | 32 | throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
33 | 33 | |
34 | - $column = $this->queryStructure->prepare($column); |
|
34 | + $column = $this->queryStructure->prepare( $column ); |
|
35 | 35 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
36 | 36 | |
37 | 37 | return $this; |
@@ -44,12 +44,12 @@ discard block |
||
44 | 44 | * @return $this |
45 | 45 | * @throws QueryException |
46 | 46 | */ |
47 | - public function orderByDesc( $column, array $allowedColumns = [] ) |
|
47 | + public function orderByDesc( $column, array $allowedColumns = [ ] ) |
|
48 | 48 | { |
49 | 49 | if ( !$this->validateColumn( $column, $allowedColumns ) ) |
50 | 50 | throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
51 | 51 | |
52 | - $column = $this->queryStructure->prepare($column); |
|
52 | + $column = $this->queryStructure->prepare( $column ); |
|
53 | 53 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column . ' DESC' ); |
54 | 54 | |
55 | 55 | return $this; |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function orderBy( $column, array $allowedColumns = [] ) |
30 | 30 | { |
31 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
32 | - throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
31 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
32 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $column = $this->queryStructure->prepare($column); |
35 | 36 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
@@ -46,8 +47,9 @@ discard block |
||
46 | 47 | */ |
47 | 48 | public function orderByDesc( $column, array $allowedColumns = [] ) |
48 | 49 | { |
49 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
50 | - throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
50 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
51 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
52 | + } |
|
51 | 53 | |
52 | 54 | $column = $this->queryStructure->prepare($column); |
53 | 55 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column . ' DESC' ); |
@@ -74,8 +76,9 @@ discard block |
||
74 | 76 | */ |
75 | 77 | private function getOrderBySyntax() |
76 | 78 | { |
77 | - if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) |
|
78 | - return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
79 | + if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) { |
|
80 | + return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
81 | + } |
|
79 | 82 | |
80 | 83 | return ''; |
81 | 84 | } |
@@ -26,11 +26,13 @@ |
||
26 | 26 | */ |
27 | 27 | protected function validateColumn( $columnName, array $allowed ) |
28 | 28 | { |
29 | - if ( is_integer( $columnName ) ) |
|
30 | - return true; |
|
29 | + if ( is_integer( $columnName ) ) { |
|
30 | + return true; |
|
31 | + } |
|
31 | 32 | |
32 | - if ( !count( $allowed ) ) |
|
33 | - return true; |
|
33 | + if ( !count( $allowed ) ) { |
|
34 | + return true; |
|
35 | + } |
|
34 | 36 | |
35 | 37 | return false; |
36 | 38 | } |
@@ -26,12 +26,12 @@ discard block |
||
26 | 26 | * @return $this |
27 | 27 | * @throws QueryException |
28 | 28 | */ |
29 | - public function groupBy( $column, array $allowedColumns = [] ) |
|
29 | + public function groupBy( $column, array $allowedColumns = [ ] ) |
|
30 | 30 | { |
31 | 31 | if ( !$this->validateColumn( $column, $allowedColumns ) ) |
32 | 32 | throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
33 | 33 | |
34 | - $column = $this->queryStructure->prepare($column); |
|
34 | + $column = $this->queryStructure->prepare( $column ); |
|
35 | 35 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
36 | 36 | |
37 | 37 | $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column ); |
@@ -46,12 +46,12 @@ discard block |
||
46 | 46 | * @return $this |
47 | 47 | * @throws QueryException |
48 | 48 | */ |
49 | - public function groupByDesc( $column, array $allowedColumns = [] ) |
|
49 | + public function groupByDesc( $column, array $allowedColumns = [ ] ) |
|
50 | 50 | { |
51 | 51 | if ( !$this->validateColumn( $column, $allowedColumns ) ) |
52 | 52 | throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
53 | 53 | |
54 | - $column = $this->queryStructure->prepare($column); |
|
54 | + $column = $this->queryStructure->prepare( $column ); |
|
55 | 55 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
56 | 56 | |
57 | 57 | $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column . ' DESC' ); |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | */ |
29 | 29 | public function groupBy( $column, array $allowedColumns = [] ) |
30 | 30 | { |
31 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
32 | - throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
31 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
32 | + throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $column = $this->queryStructure->prepare($column); |
35 | 36 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
@@ -48,8 +49,9 @@ discard block |
||
48 | 49 | */ |
49 | 50 | public function groupByDesc( $column, array $allowedColumns = [] ) |
50 | 51 | { |
51 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
52 | - throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
52 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
53 | + throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
54 | + } |
|
53 | 55 | |
54 | 56 | $column = $this->queryStructure->prepare($column); |
55 | 57 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
@@ -78,8 +80,9 @@ discard block |
||
78 | 80 | */ |
79 | 81 | private function getGroupBySyntax() |
80 | 82 | { |
81 | - if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) |
|
82 | - return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' ); |
|
83 | + if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) { |
|
84 | + return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' ); |
|
85 | + } |
|
83 | 86 | |
84 | 87 | return ''; |
85 | 88 | } |
@@ -67,8 +67,9 @@ discard block |
||
67 | 67 | public function getRowById( $id, array $fields = [] ) { |
68 | 68 | $conditions = $this->getPrimaryKeyConditions( $id ); |
69 | 69 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
70 | - foreach ( $conditions as $field => $value ) |
|
71 | - $result->whereEqual( $field, $value ); |
|
70 | + foreach ( $conditions as $field => $value ) { |
|
71 | + $result->whereEqual( $field, $value ); |
|
72 | + } |
|
72 | 73 | |
73 | 74 | return $result->first()->execute(); |
74 | 75 | } |
@@ -82,8 +83,9 @@ discard block |
||
82 | 83 | public function deleteRowById( $id ) { |
83 | 84 | $conditions = $this->getPrimaryKeyConditions( $id ); |
84 | 85 | $result = QueryBuild::delete( $this->table ); |
85 | - foreach ( $conditions as $field => $value ) |
|
86 | - $result->whereEqual( $field, $value ); |
|
86 | + foreach ( $conditions as $field => $value ) { |
|
87 | + $result->whereEqual( $field, $value ); |
|
88 | + } |
|
87 | 89 | |
88 | 90 | return $result->execute(); |
89 | 91 | } |
@@ -97,8 +99,9 @@ discard block |
||
97 | 99 | public function updateRowById( $id, array $arrayUpdater ) { |
98 | 100 | $conditions = $this->getPrimaryKeyConditions( $id ); |
99 | 101 | $result = QueryBuild::update( $this->table ); |
100 | - foreach ( $conditions as $field => $value ) |
|
101 | - $result->whereEqual( $field, $value ); |
|
102 | + foreach ( $conditions as $field => $value ) { |
|
103 | + $result->whereEqual( $field, $value ); |
|
104 | + } |
|
102 | 105 | $result->setFieldsByArray( $arrayUpdater ); |
103 | 106 | |
104 | 107 | return $result->execute(); |
@@ -120,8 +123,9 @@ discard block |
||
120 | 123 | * @throws QueryException |
121 | 124 | */ |
122 | 125 | public function getMaxOrder( $nullToZero = false ) { |
123 | - if ( empty( $this->orderField ) ) |
|
124 | - throw new QueryException( 'Order field is not defined' ); |
|
126 | + if ( empty( $this->orderField ) ) { |
|
127 | + throw new QueryException( 'Order field is not defined' ); |
|
128 | + } |
|
125 | 129 | |
126 | 130 | $result = QueryBuild::select( $this->table ) |
127 | 131 | ->fieldExpression( "MAX(`{$this->orderField}`)", "max_order_column_alias" ) |
@@ -142,8 +146,9 @@ discard block |
||
142 | 146 | * @throws QueryException |
143 | 147 | */ |
144 | 148 | public function saveOrder( $updates_ord = array() ) { |
145 | - if ( empty( $this->orderField ) ) |
|
146 | - throw new QueryException( 'Order field is not defined' ); |
|
149 | + if ( empty( $this->orderField ) ) { |
|
150 | + throw new QueryException( 'Order field is not defined' ); |
|
151 | + } |
|
147 | 152 | |
148 | 153 | $query = /** @lang text */ |
149 | 154 | "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
@@ -166,13 +171,15 @@ discard block |
||
166 | 171 | |
167 | 172 | $id = (array)$id; |
168 | 173 | |
169 | - if ( count( $this->primary ) !== count( $id ) ) |
|
170 | - throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
174 | + if ( count( $this->primary ) !== count( $id ) ) { |
|
175 | + throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
176 | + } |
|
171 | 177 | |
172 | 178 | $conditions = []; |
173 | 179 | |
174 | - foreach ( $this->primary as $index => $key ) |
|
175 | - $conditions[ $key ] = $id[ $index ]; |
|
180 | + foreach ( $this->primary as $index => $key ) { |
|
181 | + $conditions[ $key ] = $id[ $index ]; |
|
182 | + } |
|
176 | 183 | |
177 | 184 | return $conditions; |
178 | 185 | } |
@@ -42,7 +42,7 @@ discard block |
||
42 | 42 | */ |
43 | 43 | public function __construct() { |
44 | 44 | $this->table = $this->getTableName(); |
45 | - $this->primary = (array)$this->getPrimaryKey(); |
|
45 | + $this->primary = ( array ) $this->getPrimaryKey(); |
|
46 | 46 | $this->orderField = $this->getOrderField(); |
47 | 47 | } |
48 | 48 | |
@@ -69,7 +69,7 @@ discard block |
||
69 | 69 | * @return array|bool |
70 | 70 | * @throws QueryException |
71 | 71 | */ |
72 | - public function getRowById( $id, array $fields = [] ) { |
|
72 | + public function getRowById( $id, array $fields = [ ] ) { |
|
73 | 73 | $conditions = $this->getPrimaryKeyConditions( $id ); |
74 | 74 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
75 | 75 | foreach ( $conditions as $field => $value ) |
@@ -85,7 +85,7 @@ discard block |
||
85 | 85 | * @return array |
86 | 86 | * @throws QueryException |
87 | 87 | */ |
88 | - public function getFirstRowByCondition( $fieldName, $fieldValue, $fields = [] ) { |
|
88 | + public function getFirstRowByCondition( $fieldName, $fieldValue, $fields = [ ] ) { |
|
89 | 89 | return QueryBuild::select( $this->table ) |
90 | 90 | ->fields( $fields ) |
91 | 91 | ->whereEqual( $fieldName, $fieldValue ) |
@@ -132,9 +132,9 @@ discard block |
||
132 | 132 | * @throws QueryException |
133 | 133 | */ |
134 | 134 | public function updateRowsByFieldFilter( $fieldName, $fieldValue, array $arrayUpdater ) { |
135 | - return QueryBuild::update($this->table) |
|
136 | - ->whereEqual($fieldName, $fieldValue) |
|
137 | - ->setFieldsByArray($arrayUpdater) |
|
135 | + return QueryBuild::update( $this->table ) |
|
136 | + ->whereEqual( $fieldName, $fieldValue ) |
|
137 | + ->setFieldsByArray( $arrayUpdater ) |
|
138 | 138 | ->execute(); |
139 | 139 | } |
140 | 140 | |
@@ -183,14 +183,14 @@ discard block |
||
183 | 183 | throw new QueryException( 'Order field is not defined' ); |
184 | 184 | |
185 | 185 | $query = /** @lang text */ |
186 | - "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
|
186 | + "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[ 0 ]}` \r\n"; |
|
187 | 187 | foreach ( $updates_ord as $position => $id ) { |
188 | 188 | $pos = $position + 1; |
189 | 189 | $query .= " WHEN '$id' THEN '$pos' \r\n"; |
190 | 190 | } |
191 | 191 | $query .= "ELSE `{$this->orderField}` END"; |
192 | 192 | |
193 | - return PdoWrapperService::getInstance()->query( $query, [] ); |
|
193 | + return PdoWrapperService::getInstance()->query( $query, [ ] ); |
|
194 | 194 | } |
195 | 195 | |
196 | 196 | |
@@ -201,12 +201,12 @@ discard block |
||
201 | 201 | */ |
202 | 202 | protected function getPrimaryKeyConditions( $id ) { |
203 | 203 | |
204 | - $id = (array)$id; |
|
204 | + $id = ( array ) $id; |
|
205 | 205 | |
206 | 206 | if ( count( $this->primary ) !== count( $id ) ) |
207 | 207 | throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
208 | 208 | |
209 | - $conditions = []; |
|
209 | + $conditions = [ ]; |
|
210 | 210 | |
211 | 211 | foreach ( $this->primary as $index => $key ) |
212 | 212 | $conditions[ $key ] = $id[ $index ]; |
@@ -62,11 +62,11 @@ discard block |
||
62 | 62 | |
63 | 63 | private function normalizeFields( $fields ) { |
64 | 64 | $array = Arrays::flattenValues( $fields ); |
65 | - $array = (array)$array; |
|
65 | + $array = ( array ) $array; |
|
66 | 66 | $return = array(); |
67 | 67 | array_walk_recursive( $array, function( $a ) use ( &$return ) { |
68 | 68 | $a = explode( ',', $a ); |
69 | - $return[] = $a; |
|
69 | + $return[ ] = $a; |
|
70 | 70 | } ); |
71 | 71 | |
72 | 72 | return $return; |
@@ -80,7 +80,7 @@ discard block |
||
80 | 80 | return '*'; |
81 | 81 | } |
82 | 82 | |
83 | - return implode( ', ', (array)$this->queryStructure->getElement( QueryStructure::FIELDS )); |
|
83 | + return implode( ', ', ( array ) $this->queryStructure->getElement( QueryStructure::FIELDS ) ); |
|
84 | 84 | } |
85 | 85 | |
86 | 86 | } |
87 | 87 | \ No newline at end of file |