@@ -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 | } |
@@ -120,62 +120,62 @@ discard block |
||
120 | 120 | /** |
121 | 121 | * Explain |
122 | 122 | */ |
123 | - $syntax[] = $this->getExplainSyntax(); |
|
123 | + $syntax[ ] = $this->getExplainSyntax(); |
|
124 | 124 | |
125 | 125 | /** |
126 | 126 | * SELECT statement |
127 | 127 | */ |
128 | - $syntax[] = $this->statement; |
|
128 | + $syntax[ ] = $this->statement; |
|
129 | 129 | |
130 | 130 | /** |
131 | 131 | * PRIORITY |
132 | 132 | */ |
133 | - $syntax[] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
|
133 | + $syntax[ ] = $this->queryStructure->getElement( QueryStructure::PRIORITY ); |
|
134 | 134 | |
135 | 135 | /** |
136 | 136 | * DISTINCT clause |
137 | 137 | */ |
138 | - $syntax[] = $this->getDistinctSyntax(); |
|
138 | + $syntax[ ] = $this->getDistinctSyntax(); |
|
139 | 139 | |
140 | 140 | /** |
141 | 141 | * FIELDS |
142 | 142 | */ |
143 | - $syntax[] = $this->getSelectFieldsSyntax(); |
|
143 | + $syntax[ ] = $this->getSelectFieldsSyntax(); |
|
144 | 144 | |
145 | 145 | /** |
146 | 146 | * FROM table or queryStructure |
147 | 147 | */ |
148 | - $syntax[] = 'FROM ' . $this->queryStructure->getElement( QueryStructure::TABLE ); |
|
148 | + $syntax[ ] = 'FROM ' . $this->queryStructure->getElement( QueryStructure::TABLE ); |
|
149 | 149 | |
150 | 150 | /** |
151 | 151 | * JOIN CLAUSES |
152 | 152 | */ |
153 | - $syntax[] = $this->getJoinSyntax(); |
|
153 | + $syntax[ ] = $this->getJoinSyntax(); |
|
154 | 154 | |
155 | 155 | /** |
156 | 156 | * WHERE clause |
157 | 157 | */ |
158 | - $syntax[] = $this->getWhereSyntax(); |
|
158 | + $syntax[ ] = $this->getWhereSyntax(); |
|
159 | 159 | |
160 | 160 | /** |
161 | 161 | * GROUP BY clause |
162 | 162 | */ |
163 | - $syntax[] = $this->getGroupBySyntax(); |
|
163 | + $syntax[ ] = $this->getGroupBySyntax(); |
|
164 | 164 | |
165 | 165 | /** |
166 | 166 | * HAVING clause |
167 | 167 | */ |
168 | - $syntax[] = $this->getHavingSyntax(); |
|
168 | + $syntax[ ] = $this->getHavingSyntax(); |
|
169 | 169 | |
170 | 170 | /** |
171 | 171 | * ORDER BY clause |
172 | 172 | */ |
173 | - $syntax[] = $this->getOrderBySyntax(); |
|
173 | + $syntax[ ] = $this->getOrderBySyntax(); |
|
174 | 174 | |
175 | 175 | /** |
176 | 176 | * LIMIT clause |
177 | 177 | */ |
178 | - $syntax[] = $this->getLimitSyntax(); |
|
178 | + $syntax[ ] = $this->getLimitSyntax(); |
|
179 | 179 | |
180 | 180 | $syntax = implode( ' ', $syntax ); |
181 | 181 | |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | case $this->queryStructure->getElement( QueryStructure::COLUMN ): |
201 | 201 | return PdoWrapperService::getInstance()->queryFetchAll( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ), \PDO::FETCH_COLUMN ); |
202 | 202 | default: |
203 | - return PdoWrapperService::getInstance()->queryFetchAll($this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ), \PDO::FETCH_ASSOC); |
|
203 | + return PdoWrapperService::getInstance()->queryFetchAll( $this->getSyntax(), $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ), \PDO::FETCH_ASSOC ); |
|
204 | 204 | } |
205 | 205 | } |
206 | 206 |
@@ -60,7 +60,7 @@ discard block |
||
60 | 60 | /** |
61 | 61 | * @var array |
62 | 62 | */ |
63 | - private static $usedInstanceIds = []; |
|
63 | + private static $usedInstanceIds = [ ]; |
|
64 | 64 | |
65 | 65 | /** |
66 | 66 | * @var array |
@@ -97,7 +97,7 @@ discard block |
||
97 | 97 | self::EXPLAIN => 0, |
98 | 98 | self::STATEMENT => '', |
99 | 99 | self::PRIORITY => '', |
100 | - self::FIELDS => [], |
|
100 | + self::FIELDS => [ ], |
|
101 | 101 | self::SET_FIELDS => array(), |
102 | 102 | self::WHERE => array(), |
103 | 103 | self::HAVING => array(), |
@@ -132,7 +132,7 @@ discard block |
||
132 | 132 | while ( in_array( $instance, self::$usedInstanceIds ) ) { |
133 | 133 | $instance = QueryHelper::random( 5 ); |
134 | 134 | } |
135 | - self::$usedInstanceIds[] = $instance; |
|
135 | + self::$usedInstanceIds[ ] = $instance; |
|
136 | 136 | |
137 | 137 | return $instance; |
138 | 138 | } |
@@ -179,7 +179,7 @@ discard block |
||
179 | 179 | return true; |
180 | 180 | |
181 | 181 | if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) |
182 | - $this->syntaxEL[ $name ][] = $value; |
|
182 | + $this->syntaxEL[ $name ][ ] = $value; |
|
183 | 183 | else |
184 | 184 | $this->syntaxEL[ $name ] = $value; |
185 | 185 | |
@@ -226,7 +226,7 @@ discard block |
||
226 | 226 | * @param string $search |
227 | 227 | * @return string |
228 | 228 | */ |
229 | - public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
|
229 | + public function bindParamsExpression( $expression, array $params = [ ], $search = '?' ) |
|
230 | 230 | { |
231 | 231 | if ( !count( $params ) ) |
232 | 232 | return $expression; |
@@ -237,12 +237,12 @@ discard block |
||
237 | 237 | $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
238 | 238 | |
239 | 239 | $i = 0; |
240 | - $arrayReturn = []; |
|
240 | + $arrayReturn = [ ]; |
|
241 | 241 | $expressionToArray = explode( $search, $expression ); |
242 | 242 | |
243 | 243 | foreach ( $expressionToArray as $sub ) { |
244 | - $arrayReturn[] = $sub; |
|
245 | - $arrayReturn[] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : ''; |
|
244 | + $arrayReturn[ ] = $sub; |
|
245 | + $arrayReturn[ ] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : ''; |
|
246 | 246 | $i++; |
247 | 247 | } |
248 | 248 |
@@ -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 |
@@ -28,9 +28,9 @@ |
||
28 | 28 | */ |
29 | 29 | public function setField( $fieldName, $fieldValue ) |
30 | 30 | { |
31 | - $fieldName = $this->queryStructure->prepare($fieldName); |
|
31 | + $fieldName = $this->queryStructure->prepare( $fieldName ); |
|
32 | 32 | $valuePdoString = $this->queryStructure->bindParam( $fieldName, $fieldValue ); |
33 | - $this->queryStructure->setElement( QueryStructure::SET_FIELDS, $this->queryStructure->prepare($fieldName) . " = $valuePdoString" ); |
|
33 | + $this->queryStructure->setElement( QueryStructure::SET_FIELDS, $this->queryStructure->prepare( $fieldName ) . " = $valuePdoString" ); |
|
34 | 34 | |
35 | 35 | return $this; |
36 | 36 | } |