@@ -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 | } |
@@ -37,7 +37,7 @@ discard block |
||
| 37 | 37 | */ |
| 38 | 38 | public function __construct() { |
| 39 | 39 | $this->table = $this->getTableName(); |
| 40 | - $this->primary = (array)$this->getPrimaryKey(); |
|
| 40 | + $this->primary = ( array ) $this->getPrimaryKey(); |
|
| 41 | 41 | $this->orderField = $this->getOrderField(); |
| 42 | 42 | } |
| 43 | 43 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | * @return array|bool |
| 65 | 65 | * @throws QueryException |
| 66 | 66 | */ |
| 67 | - public function getRowById( $id, array $fields = [] ) { |
|
| 67 | + public function getRowById( $id, array $fields = [ ] ) { |
|
| 68 | 68 | $conditions = $this->getPrimaryKeyConditions( $id ); |
| 69 | 69 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
| 70 | 70 | foreach ( $conditions as $field => $value ) |
@@ -146,14 +146,14 @@ discard block |
||
| 146 | 146 | throw new QueryException( 'Order field is not defined' ); |
| 147 | 147 | |
| 148 | 148 | $query = /** @lang text */ |
| 149 | - "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
|
| 149 | + "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[ 0 ]}` \r\n"; |
|
| 150 | 150 | foreach ( $updates_ord as $position => $id ) { |
| 151 | 151 | $pos = $position + 1; |
| 152 | 152 | $query .= " WHEN '$id' THEN '$pos' \r\n"; |
| 153 | 153 | } |
| 154 | 154 | $query .= "ELSE `{$this->orderField}` END"; |
| 155 | 155 | |
| 156 | - return PdoWrapperService::getInstance()->query( $query, [] ); |
|
| 156 | + return PdoWrapperService::getInstance()->query( $query, [ ] ); |
|
| 157 | 157 | } |
| 158 | 158 | |
| 159 | 159 | |
@@ -164,12 +164,12 @@ discard block |
||
| 164 | 164 | */ |
| 165 | 165 | protected function getPrimaryKeyConditions( $id ) { |
| 166 | 166 | |
| 167 | - $id = (array)$id; |
|
| 167 | + $id = ( array ) $id; |
|
| 168 | 168 | |
| 169 | 169 | if ( count( $this->primary ) !== count( $id ) ) |
| 170 | 170 | throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
| 171 | 171 | |
| 172 | - $conditions = []; |
|
| 172 | + $conditions = [ ]; |
|
| 173 | 173 | |
| 174 | 174 | foreach ( $this->primary as $index => $key ) |
| 175 | 175 | $conditions[ $key ] = $id[ $index ]; |
@@ -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 | } |
@@ -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( ', ', $this->queryStructure->getElement( QueryStructure::FIELDS )); |
|
| 83 | + return implode( ', ', $this->queryStructure->getElement( QueryStructure::FIELDS ) ); |
|
| 84 | 84 | } |
| 85 | 85 | |
| 86 | 86 | } |
| 87 | 87 | \ No newline at end of file |