@@ -52,7 +52,7 @@ |
||
| 52 | 52 | if ( '' === $table ) |
| 53 | 53 | throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
| 54 | 54 | |
| 55 | - return QueryHelper::addBacktick($table); |
|
| 55 | + return QueryHelper::addBacktick( $table ); |
|
| 56 | 56 | } |
| 57 | 57 | |
| 58 | 58 | /** |
@@ -49,8 +49,9 @@ discard block |
||
| 49 | 49 | { |
| 50 | 50 | $table = trim( $table ); |
| 51 | 51 | |
| 52 | - if ( '' === $table ) |
|
| 53 | - throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 52 | + if ( '' === $table ) { |
|
| 53 | + throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 54 | + } |
|
| 54 | 55 | |
| 55 | 56 | return QueryHelper::addBacktick($table); |
| 56 | 57 | } |
@@ -62,11 +63,13 @@ discard block |
||
| 62 | 63 | */ |
| 63 | 64 | private function validateTableSubQuery( $table ) |
| 64 | 65 | { |
| 65 | - if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) |
|
| 66 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 66 | + if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) { |
|
| 67 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 68 | + } |
|
| 67 | 69 | |
| 68 | - if ( !is_a( $table, QuerySelect::class ) ) |
|
| 69 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 70 | + if ( !is_a( $table, QuerySelect::class ) ) { |
|
| 71 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
| 72 | + } |
|
| 70 | 73 | |
| 71 | 74 | return $table; |
| 72 | 75 | } |
@@ -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 | } |
@@ -38,7 +38,7 @@ discard block |
||
| 38 | 38 | public function __construct() |
| 39 | 39 | { |
| 40 | 40 | $this->table = $this->getTableName(); |
| 41 | - $this->primary = (array)$this->getPrimaryKey(); |
|
| 41 | + $this->primary = ( array ) $this->getPrimaryKey(); |
|
| 42 | 42 | $this->orderField = $this->getOrderField(); |
| 43 | 43 | } |
| 44 | 44 | |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | * @return array|bool |
| 66 | 66 | * @throws QueryException |
| 67 | 67 | */ |
| 68 | - public function getRowById( $id, array $fields = [] ) |
|
| 68 | + public function getRowById( $id, array $fields = [ ] ) |
|
| 69 | 69 | { |
| 70 | 70 | $conditions = $this->getPrimaryKeyConditions( $id ); |
| 71 | 71 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
@@ -130,14 +130,14 @@ discard block |
||
| 130 | 130 | throw new QueryException( 'Order field is not defined' ); |
| 131 | 131 | |
| 132 | 132 | $query = /** @lang text */ |
| 133 | - "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
|
| 133 | + "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[ 0 ]}` \r\n"; |
|
| 134 | 134 | foreach ( $updates_ord as $position => $id ) { |
| 135 | 135 | $pos = $position + 1; |
| 136 | 136 | $query .= " WHEN '$id' THEN '$pos' \r\n"; |
| 137 | 137 | } |
| 138 | 138 | $query .= "ELSE `{$this->orderField}` END"; |
| 139 | 139 | |
| 140 | - return PdoWrapperService::getInstance()->query($query, []); |
|
| 140 | + return PdoWrapperService::getInstance()->query( $query, [ ] ); |
|
| 141 | 141 | } |
| 142 | 142 | |
| 143 | 143 | |
@@ -149,12 +149,12 @@ discard block |
||
| 149 | 149 | protected function getPrimaryKeyConditions( $id ) |
| 150 | 150 | { |
| 151 | 151 | |
| 152 | - $id = (array)$id; |
|
| 152 | + $id = ( array ) $id; |
|
| 153 | 153 | |
| 154 | 154 | if ( count( $this->primary ) !== count( $id ) ) |
| 155 | 155 | throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
| 156 | 156 | |
| 157 | - $conditions = []; |
|
| 157 | + $conditions = [ ]; |
|
| 158 | 158 | |
| 159 | 159 | foreach ( $this->primary as $index => $key ) |
| 160 | 160 | $conditions[ $key ] = $id[ $index ]; |
@@ -69,8 +69,9 @@ discard block |
||
| 69 | 69 | { |
| 70 | 70 | $conditions = $this->getPrimaryKeyConditions( $id ); |
| 71 | 71 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
| 72 | - foreach ( $conditions as $field => $value ) |
|
| 73 | - $result->whereEqual( $field, $value ); |
|
| 72 | + foreach ( $conditions as $field => $value ) { |
|
| 73 | + $result->whereEqual( $field, $value ); |
|
| 74 | + } |
|
| 74 | 75 | |
| 75 | 76 | return $result->first()->execute(); |
| 76 | 77 | } |
@@ -85,8 +86,9 @@ discard block |
||
| 85 | 86 | { |
| 86 | 87 | $conditions = $this->getPrimaryKeyConditions( $id ); |
| 87 | 88 | $result = QueryBuild::delete( $this->table ); |
| 88 | - foreach ( $conditions as $field => $value ) |
|
| 89 | - $result->whereEqual( $field, $value ); |
|
| 89 | + foreach ( $conditions as $field => $value ) { |
|
| 90 | + $result->whereEqual( $field, $value ); |
|
| 91 | + } |
|
| 90 | 92 | |
| 91 | 93 | return $result->execute(); |
| 92 | 94 | } |
@@ -101,8 +103,9 @@ discard block |
||
| 101 | 103 | { |
| 102 | 104 | $conditions = $this->getPrimaryKeyConditions( $id ); |
| 103 | 105 | $result = QueryBuild::update( $this->table ); |
| 104 | - foreach ( $conditions as $field => $value ) |
|
| 105 | - $result->whereEqual( $field, $value ); |
|
| 106 | + foreach ( $conditions as $field => $value ) { |
|
| 107 | + $result->whereEqual( $field, $value ); |
|
| 108 | + } |
|
| 106 | 109 | $result->setFieldsByArray( $arrayUpdater ); |
| 107 | 110 | |
| 108 | 111 | return $result->execute(); |
@@ -126,8 +129,9 @@ discard block |
||
| 126 | 129 | */ |
| 127 | 130 | public function saveOrder( $updates_ord = array() ) |
| 128 | 131 | { |
| 129 | - if ( empty( $this->orderField ) ) |
|
| 130 | - throw new QueryException( 'Order field is not defined' ); |
|
| 132 | + if ( empty( $this->orderField ) ) { |
|
| 133 | + throw new QueryException( 'Order field is not defined' ); |
|
| 134 | + } |
|
| 131 | 135 | |
| 132 | 136 | $query = /** @lang text */ |
| 133 | 137 | "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
@@ -151,13 +155,15 @@ discard block |
||
| 151 | 155 | |
| 152 | 156 | $id = (array)$id; |
| 153 | 157 | |
| 154 | - if ( count( $this->primary ) !== count( $id ) ) |
|
| 155 | - throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
| 158 | + if ( count( $this->primary ) !== count( $id ) ) { |
|
| 159 | + throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
| 160 | + } |
|
| 156 | 161 | |
| 157 | 162 | $conditions = []; |
| 158 | 163 | |
| 159 | - foreach ( $this->primary as $index => $key ) |
|
| 160 | - $conditions[ $key ] = $id[ $index ]; |
|
| 164 | + foreach ( $this->primary as $index => $key ) { |
|
| 165 | + $conditions[ $key ] = $id[ $index ]; |
|
| 166 | + } |
|
| 161 | 167 | |
| 162 | 168 | return $conditions; |
| 163 | 169 | } |