@@ -24,7 +24,7 @@ |
||
24 | 24 | */ |
25 | 25 | public function setField( $fieldName, $fieldValue ) |
26 | 26 | { |
27 | - $fieldName = $this->queryStructure->prepare($fieldName); |
|
27 | + $fieldName = $this->queryStructure->prepare( $fieldName ); |
|
28 | 28 | $valuePdoString = $this->queryStructure->bindParam( $fieldName, $fieldValue ); |
29 | 29 | $this->queryStructure->setElement( QueryStructure::SET_FIELDS, "$fieldName = $valuePdoString" ); |
30 | 30 |
@@ -63,14 +63,14 @@ |
||
63 | 63 | */ |
64 | 64 | private function prepareArrayFields( $fieldsArray = array() ) |
65 | 65 | { |
66 | - $prepareArray = []; |
|
66 | + $prepareArray = [ ]; |
|
67 | 67 | |
68 | 68 | foreach ( $fieldsArray as $field ) { |
69 | 69 | if ( gettype( $field ) !== QueryStructure::ELEMENT_TYPE_STRING ) |
70 | 70 | throw new QueryException( 'Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD ); |
71 | 71 | |
72 | 72 | if ( '' !== trim( $field ) ) |
73 | - $prepareArray[] = $this->queryStructure->prepare( $field ); |
|
73 | + $prepareArray[ ] = $this->queryStructure->prepare( $field ); |
|
74 | 74 | } |
75 | 75 | |
76 | 76 | return $prepareArray; |
@@ -30,10 +30,11 @@ discard block |
||
30 | 30 | |
31 | 31 | $fields = $this->prepareArrayFields( $fields ); |
32 | 32 | |
33 | - if ( count( $fields ) ) |
|
34 | - $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
|
35 | - else |
|
36 | - $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
33 | + if ( count( $fields ) ) { |
|
34 | + $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
|
35 | + } else { |
|
36 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
37 | + } |
|
37 | 38 | break; |
38 | 39 | |
39 | 40 | case QueryStructure::ELEMENT_TYPE_STRING: |
@@ -43,9 +44,9 @@ discard block |
||
43 | 44 | $fields = explode( ',', $fields ); |
44 | 45 | $fields = $this->prepareArrayFields( $fields ); |
45 | 46 | $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
47 | + } else { |
|
48 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
46 | 49 | } |
47 | - else |
|
48 | - $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
49 | 50 | break; |
50 | 51 | |
51 | 52 | default: |
@@ -66,11 +67,13 @@ discard block |
||
66 | 67 | $prepareArray = []; |
67 | 68 | |
68 | 69 | foreach ( $fieldsArray as $field ) { |
69 | - if ( gettype( $field ) !== QueryStructure::ELEMENT_TYPE_STRING ) |
|
70 | - throw new QueryException( 'Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD ); |
|
70 | + if ( gettype( $field ) !== QueryStructure::ELEMENT_TYPE_STRING ) { |
|
71 | + throw new QueryException( 'Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD ); |
|
72 | + } |
|
71 | 73 | |
72 | - if ( '' !== trim( $field ) ) |
|
73 | - $prepareArray[] = $this->queryStructure->prepare( $field ); |
|
74 | + if ( '' !== trim( $field ) ) { |
|
75 | + $prepareArray[] = $this->queryStructure->prepare( $field ); |
|
76 | + } |
|
74 | 77 | } |
75 | 78 | |
76 | 79 | return $prepareArray; |
@@ -139,7 +139,7 @@ discard block |
||
139 | 139 | |
140 | 140 | $pdoArray = array(); |
141 | 141 | foreach ( $value as $item ) { |
142 | - $pdoArray[] = $this->queryStructure->bindParam( 'a', $item ); |
|
142 | + $pdoArray[ ] = $this->queryStructure->bindParam( 'a', $item ); |
|
143 | 143 | } |
144 | 144 | $body = [ |
145 | 145 | $field, |
@@ -216,7 +216,7 @@ discard block |
||
216 | 216 | throw new QueryException( 'Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
217 | 217 | |
218 | 218 | if ( count( $param ) == 2 ) |
219 | - $param[] = '='; |
|
219 | + $param[ ] = '='; |
|
220 | 220 | |
221 | 221 | $param[ 0 ] = $this->queryStructure->prepare( $param[ 0 ] ); |
222 | 222 | $param[ 2 ] = trim( strtoupper( $param[ 2 ] ) ); |
@@ -103,10 +103,11 @@ discard block |
||
103 | 103 | |
104 | 104 | private function makeInCondition() |
105 | 105 | { |
106 | - if ( is_a( $this->temporaryParam[ 1 ], QuerySelect::class ) ) |
|
107 | - $this->inQuerySelect(); |
|
108 | - elseif ( is_array( $this->temporaryParam[ 1 ] ) ) |
|
109 | - $this->inArray(); |
|
106 | + if ( is_a( $this->temporaryParam[ 1 ], QuerySelect::class ) ) { |
|
107 | + $this->inQuerySelect(); |
|
108 | + } elseif ( is_array( $this->temporaryParam[ 1 ] ) ) { |
|
109 | + $this->inArray(); |
|
110 | + } |
|
110 | 111 | } |
111 | 112 | |
112 | 113 | private function inQuerySelect() |
@@ -182,8 +183,9 @@ discard block |
||
182 | 183 | */ |
183 | 184 | private function getWhereAndHavingSyntax( $clauseType ) |
184 | 185 | { |
185 | - if ( count( $this->queryStructure->getElement( $clauseType ) ) == 0 ) |
|
186 | - return ''; |
|
186 | + if ( count( $this->queryStructure->getElement( $clauseType ) ) == 0 ) { |
|
187 | + return ''; |
|
188 | + } |
|
187 | 189 | |
188 | 190 | $where = ''; |
189 | 191 | $last_type = 'where_start'; |
@@ -212,11 +214,13 @@ discard block |
||
212 | 214 | */ |
213 | 215 | private function validateWhereParam( $param ) |
214 | 216 | { |
215 | - if ( count( $param ) < 2 ) |
|
216 | - throw new QueryException( 'Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
|
217 | + if ( count( $param ) < 2 ) { |
|
218 | + throw new QueryException( 'Invalid where array!', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
|
219 | + } |
|
217 | 220 | |
218 | - if ( count( $param ) == 2 ) |
|
219 | - $param[] = '='; |
|
221 | + if ( count( $param ) == 2 ) { |
|
222 | + $param[] = '='; |
|
223 | + } |
|
220 | 224 | |
221 | 225 | $param[ 0 ] = $this->queryStructure->prepare( $param[ 0 ] ); |
222 | 226 | $param[ 2 ] = trim( strtoupper( $param[ 2 ] ) ); |
@@ -24,9 +24,9 @@ discard block |
||
24 | 24 | * @return $this |
25 | 25 | * @throws QueryException |
26 | 26 | */ |
27 | - public function orderBy( $column, array $allowedColumns = [] ) |
|
27 | + public function orderBy( $column, array $allowedColumns = [ ] ) |
|
28 | 28 | { |
29 | - $column = $this->queryStructure->prepare($column); |
|
29 | + $column = $this->queryStructure->prepare( $column ); |
|
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 ); |
@@ -43,9 +43,9 @@ discard block |
||
43 | 43 | * @return $this |
44 | 44 | * @throws QueryException |
45 | 45 | */ |
46 | - public function orderByDesc( $column, array $allowedColumns = [] ) |
|
46 | + public function orderByDesc( $column, array $allowedColumns = [ ] ) |
|
47 | 47 | { |
48 | - $column = $this->queryStructure->prepare($column); |
|
48 | + $column = $this->queryStructure->prepare( $column ); |
|
49 | 49 | |
50 | 50 | if ( !$this->validateColumn( $column, $allowedColumns ) ) |
51 | 51 | throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | { |
29 | 29 | $column = $this->queryStructure->prepare($column); |
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 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column ); |
35 | 36 | |
@@ -47,8 +48,9 @@ discard block |
||
47 | 48 | { |
48 | 49 | $column = $this->queryStructure->prepare($column); |
49 | 50 | |
50 | - if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
51 | - throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
51 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
52 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
53 | + } |
|
52 | 54 | |
53 | 55 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column . ' DESC' ); |
54 | 56 | |
@@ -73,8 +75,9 @@ discard block |
||
73 | 75 | */ |
74 | 76 | private function getOrderBySyntax() |
75 | 77 | { |
76 | - if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) |
|
77 | - return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
78 | + if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) { |
|
79 | + return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
80 | + } |
|
78 | 81 | |
79 | 82 | return ''; |
80 | 83 | } |
@@ -97,8 +97,9 @@ discard block |
||
97 | 97 | { |
98 | 98 | $this->syntaxEL = $this->init(); |
99 | 99 | |
100 | - foreach ( $this->syntaxEL as $name => $value ) |
|
101 | - $this->typeEL[ $name ] = gettype( $value ); |
|
100 | + foreach ( $this->syntaxEL as $name => $value ) { |
|
101 | + $this->typeEL[ $name ] = gettype( $value ); |
|
102 | + } |
|
102 | 103 | |
103 | 104 | } |
104 | 105 | |
@@ -184,16 +185,19 @@ discard block |
||
184 | 185 | */ |
185 | 186 | public function setElement( $name, $value ) |
186 | 187 | { |
187 | - if ( !array_key_exists( $name, $this->syntaxEL ) ) |
|
188 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
188 | + if ( !array_key_exists( $name, $this->syntaxEL ) ) { |
|
189 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
190 | + } |
|
189 | 191 | |
190 | - if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) |
|
191 | - return true; |
|
192 | + if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) { |
|
193 | + return true; |
|
194 | + } |
|
192 | 195 | |
193 | - if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) |
|
194 | - $this->syntaxEL[ $name ][] = $value; |
|
195 | - else |
|
196 | - $this->syntaxEL[ $name ] = $value; |
|
196 | + if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) { |
|
197 | + $this->syntaxEL[ $name ][] = $value; |
|
198 | + } else { |
|
199 | + $this->syntaxEL[ $name ] = $value; |
|
200 | + } |
|
197 | 201 | |
198 | 202 | return true; |
199 | 203 | } |
@@ -206,8 +210,9 @@ discard block |
||
206 | 210 | */ |
207 | 211 | public function replaceElement( $elementName, $elementValue ) |
208 | 212 | { |
209 | - if ( !array_key_exists( $elementName, $this->syntaxEL ) ) |
|
210 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
213 | + if ( !array_key_exists( $elementName, $this->syntaxEL ) ) { |
|
214 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
215 | + } |
|
211 | 216 | |
212 | 217 | $this->syntaxEL[ $elementName ] = $elementValue; |
213 | 218 | } |
@@ -240,11 +245,13 @@ discard block |
||
240 | 245 | */ |
241 | 246 | public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
242 | 247 | { |
243 | - if ( !count( $params ) ) |
|
244 | - return $expression; |
|
248 | + if ( !count( $params ) ) { |
|
249 | + return $expression; |
|
250 | + } |
|
245 | 251 | |
246 | - if ( strpos( $expression, $search ) === false ) |
|
247 | - return $expression; |
|
252 | + if ( strpos( $expression, $search ) === false ) { |
|
253 | + return $expression; |
|
254 | + } |
|
248 | 255 | |
249 | 256 | $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
250 | 257 | |
@@ -277,8 +284,9 @@ discard block |
||
277 | 284 | public function prepare( $fieldName = '' ) |
278 | 285 | { |
279 | 286 | $fieldName = trim( $fieldName ); |
280 | - if ( in_array( $fieldName, $this->reserved ) ) |
|
281 | - $fieldName = '`' . $fieldName . '`'; |
|
287 | + if ( in_array( $fieldName, $this->reserved ) ) { |
|
288 | + $fieldName = '`' . $fieldName . '`'; |
|
289 | + } |
|
282 | 290 | |
283 | 291 | return $fieldName; |
284 | 292 | } |