@@ -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; |
@@ -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 ] ) ); |
@@ -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 | } |