@@ -85,8 +85,9 @@ discard block |
||
85 | 85 | { |
86 | 86 | $this->syntaxEL = $this->init(); |
87 | 87 | |
88 | - foreach ( $this->syntaxEL as $name => $value ) |
|
89 | - $this->typeEL[ $name ] = gettype( $value ); |
|
88 | + foreach ( $this->syntaxEL as $name => $value ) { |
|
89 | + $this->typeEL[ $name ] = gettype( $value ); |
|
90 | + } |
|
90 | 91 | |
91 | 92 | } |
92 | 93 | |
@@ -172,16 +173,19 @@ discard block |
||
172 | 173 | */ |
173 | 174 | public function setElement( $name, $value ) |
174 | 175 | { |
175 | - if ( !array_key_exists( $name, $this->syntaxEL ) ) |
|
176 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
176 | + if ( !array_key_exists( $name, $this->syntaxEL ) ) { |
|
177 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
178 | + } |
|
177 | 179 | |
178 | - if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) |
|
179 | - return true; |
|
180 | + if ( $name == self::TABLE && is_a( $value, QueryStatement::class ) ) { |
|
181 | + return true; |
|
182 | + } |
|
180 | 183 | |
181 | - if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) |
|
182 | - $this->syntaxEL[ $name ][] = $value; |
|
183 | - else |
|
184 | - $this->syntaxEL[ $name ] = $value; |
|
184 | + if ( $this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY ) { |
|
185 | + $this->syntaxEL[ $name ][] = $value; |
|
186 | + } else { |
|
187 | + $this->syntaxEL[ $name ] = $value; |
|
188 | + } |
|
185 | 189 | |
186 | 190 | return true; |
187 | 191 | } |
@@ -194,8 +198,9 @@ discard block |
||
194 | 198 | */ |
195 | 199 | public function replaceElement( $elementName, $elementValue ) |
196 | 200 | { |
197 | - if ( !array_key_exists( $elementName, $this->syntaxEL ) ) |
|
198 | - throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
201 | + if ( !array_key_exists( $elementName, $this->syntaxEL ) ) { |
|
202 | + throw new QueryException( 'Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND ); |
|
203 | + } |
|
199 | 204 | |
200 | 205 | $this->syntaxEL[ $elementName ] = $elementValue; |
201 | 206 | } |
@@ -243,11 +248,13 @@ discard block |
||
243 | 248 | */ |
244 | 249 | public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
245 | 250 | { |
246 | - if ( !count( $params ) ) |
|
247 | - return $expression; |
|
251 | + if ( !count( $params ) ) { |
|
252 | + return $expression; |
|
253 | + } |
|
248 | 254 | |
249 | - if ( strpos( $expression, $search ) === false ) |
|
250 | - return $expression; |
|
255 | + if ( strpos( $expression, $search ) === false ) { |
|
256 | + return $expression; |
|
257 | + } |
|
251 | 258 | |
252 | 259 | $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
253 | 260 |
@@ -46,22 +46,26 @@ |
||
46 | 46 | { |
47 | 47 | $table = trim( $table ); |
48 | 48 | |
49 | - if ( '' === $table ) |
|
50 | - throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
49 | + if ( '' === $table ) { |
|
50 | + throw new QueryException( 'Table name is empty string!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
51 | + } |
|
51 | 52 | |
52 | - if ( DbConfig::getInstance()->useTablePrefix() ) |
|
53 | - $table = str_ireplace( '::', DbConfig::getInstance()->getTablePrefix(), $table ); |
|
53 | + if ( DbConfig::getInstance()->useTablePrefix() ) { |
|
54 | + $table = str_ireplace( '::', DbConfig::getInstance()->getTablePrefix(), $table ); |
|
55 | + } |
|
54 | 56 | |
55 | 57 | return QueryHelper::addBacktick($table); |
56 | 58 | } |
57 | 59 | |
58 | 60 | private function validateTableSubQuery( $table ) |
59 | 61 | { |
60 | - if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) |
|
61 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
62 | + if ( $this->statement !== QueryStatement::QUERY_STATEMENT_SELECT ) { |
|
63 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
64 | + } |
|
62 | 65 | |
63 | - if ( !is_a( $table, QuerySelect::class ) ) |
|
64 | - throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
66 | + if ( !is_a( $table, QuerySelect::class ) ) { |
|
67 | + throw new QueryException( 'Invalid subQuery statement!', QueryException::QUERY_ERROR_INVALID_TABLE_STATEMENT ); |
|
68 | + } |
|
65 | 69 | |
66 | 70 | return $table; |
67 | 71 | } |
@@ -28,8 +28,9 @@ discard block |
||
28 | 28 | { |
29 | 29 | $limit = trim( $limit ); |
30 | 30 | |
31 | - if ( !QueryHelper::isInteger( $limit ) ) |
|
32 | - throw new QueryException( 'Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT ); |
|
31 | + if ( !QueryHelper::isInteger( $limit ) ) { |
|
32 | + throw new QueryException( 'Invalid Limit value', QueryException::QUERY_ERROR_INVALID_LIMIT ); |
|
33 | + } |
|
33 | 34 | |
34 | 35 | $limit = $this->queryStructure->bindParam('lim', (int)$limit); |
35 | 36 | |
@@ -41,8 +42,9 @@ discard block |
||
41 | 42 | |
42 | 43 | $offset = trim( $offset ); |
43 | 44 | |
44 | - if ( !QueryHelper::isInteger( $offset ) ) |
|
45 | - throw new QueryException( 'Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET ); |
|
45 | + if ( !QueryHelper::isInteger( $offset ) ) { |
|
46 | + throw new QueryException( 'Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET ); |
|
47 | + } |
|
46 | 48 | |
47 | 49 | $offset = $this->queryStructure->bindParam('ofs', (int)$offset); |
48 | 50 | |
@@ -53,8 +55,9 @@ discard block |
||
53 | 55 | |
54 | 56 | private function getLimitSyntax() |
55 | 57 | { |
56 | - if ( !$this->queryStructure->getElement( QueryStructure::LIMIT ) ) |
|
57 | - return ''; |
|
58 | + if ( !$this->queryStructure->getElement( QueryStructure::LIMIT ) ) { |
|
59 | + return ''; |
|
60 | + } |
|
58 | 61 | |
59 | 62 | return 'LIMIT ' . $this->queryStructure->getElement( QueryStructure::LIMIT ); |
60 | 63 | } |
@@ -19,8 +19,9 @@ |
||
19 | 19 | */ |
20 | 20 | public static function getInstance() |
21 | 21 | { |
22 | - if ( is_null( self::$instance ) ) |
|
23 | - self::$instance = new self(); |
|
22 | + if ( is_null( self::$instance ) ) { |
|
23 | + self::$instance = new self(); |
|
24 | + } |
|
24 | 25 | |
25 | 26 | return self::$instance; |
26 | 27 | } |
@@ -31,10 +31,11 @@ discard block |
||
31 | 31 | |
32 | 32 | $fields = $this->prepareArrayFields( $fields ); |
33 | 33 | |
34 | - if ( count( $fields ) ) |
|
35 | - $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
|
36 | - else |
|
37 | - $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
34 | + if ( count( $fields ) ) { |
|
35 | + $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
|
36 | + } else { |
|
37 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
38 | + } |
|
38 | 39 | break; |
39 | 40 | |
40 | 41 | case QueryStructure::ELEMENT_TYPE_STRING: |
@@ -44,9 +45,9 @@ discard block |
||
44 | 45 | $fields = explode( ',', $fields ); |
45 | 46 | $fields = $this->prepareArrayFields( $fields ); |
46 | 47 | $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); |
48 | + } else { |
|
49 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
47 | 50 | } |
48 | - else |
|
49 | - $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
50 | 51 | break; |
51 | 52 | |
52 | 53 | default: |
@@ -108,8 +109,7 @@ discard block |
||
108 | 109 | |
109 | 110 | if ( count( $fieldArray ) === 1 ) { |
110 | 111 | return $this->queryStructure->prepare( trim( $fieldArray[ 0 ] ) ); |
111 | - } |
|
112 | - else { |
|
112 | + } else { |
|
113 | 113 | return $this->queryStructure->prepare( trim( $fieldArray[ 0 ] ) ) . ' ' . $this->queryStructure->prepare( trim( $fieldArray[ 1 ] ) ); |
114 | 114 | } |
115 | 115 |
@@ -57,8 +57,9 @@ discard block |
||
57 | 57 | $newArray = array(); |
58 | 58 | foreach ( $brutArray as $value ) { |
59 | 59 | $value = trim( $value ); |
60 | - if ( '' !== $value ) |
|
61 | - $newArray[] = $value; |
|
60 | + if ( '' !== $value ) { |
|
61 | + $newArray[] = $value; |
|
62 | + } |
|
62 | 63 | } |
63 | 64 | |
64 | 65 | return $newArray; |
@@ -110,8 +111,9 @@ discard block |
||
110 | 111 | $characters = 'abcdefghijklmnopqrstuvwxyz'; |
111 | 112 | $charactersLength = strlen( $characters ); |
112 | 113 | $randomString = ''; |
113 | - for ( $i = 0; $i < $length; $i++ ) |
|
114 | - $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
114 | + for ( $i = 0; $i < $length; $i++ ) { |
|
115 | + $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
116 | + } |
|
115 | 117 | |
116 | 118 | return str_shuffle( $randomString ); |
117 | 119 | } |
@@ -125,8 +127,9 @@ discard block |
||
125 | 127 | $stringArray = explode( '.', $string ); |
126 | 128 | foreach ( $stringArray as $part ) { |
127 | 129 | $part = self::clearMultipleSpaces( $part ); |
128 | - if ( empty( $part ) ) |
|
129 | - continue; |
|
130 | + if ( empty( $part ) ) { |
|
131 | + continue; |
|
132 | + } |
|
130 | 133 | $stringArrayBacktick[] = '`' . $part . '`'; |
131 | 134 | } |
132 | 135 |
@@ -50,8 +50,9 @@ discard block |
||
50 | 50 | $this->setPrimaryKey(); |
51 | 51 | $this->setOrderField(); |
52 | 52 | |
53 | - if ( !is_array( $this->primary ) ) |
|
54 | - $this->primary = [ $this->primary ]; |
|
53 | + if ( !is_array( $this->primary ) ) { |
|
54 | + $this->primary = [ $this->primary ]; |
|
55 | + } |
|
55 | 56 | } |
56 | 57 | |
57 | 58 | /** |
@@ -64,8 +65,9 @@ discard block |
||
64 | 65 | { |
65 | 66 | $conditions = $this->getPrimaryKeyConditions( $id ); |
66 | 67 | $result = QueryBuild::select( $this->table )->fields( $fields ); |
67 | - foreach ( $conditions as $field => $value ) |
|
68 | - $result->whereEqual( $field, $value ); |
|
68 | + foreach ( $conditions as $field => $value ) { |
|
69 | + $result->whereEqual( $field, $value ); |
|
70 | + } |
|
69 | 71 | |
70 | 72 | return $result->first()->execute(); |
71 | 73 | } |
@@ -80,8 +82,9 @@ discard block |
||
80 | 82 | { |
81 | 83 | $conditions = $this->getPrimaryKeyConditions( $id ); |
82 | 84 | $result = QueryBuild::delete( $this->table ); |
83 | - foreach ( $conditions as $field => $value ) |
|
84 | - $result->whereEqual( $field, $value ); |
|
85 | + foreach ( $conditions as $field => $value ) { |
|
86 | + $result->whereEqual( $field, $value ); |
|
87 | + } |
|
85 | 88 | |
86 | 89 | return $result->execute(); |
87 | 90 | } |
@@ -96,8 +99,9 @@ discard block |
||
96 | 99 | { |
97 | 100 | $conditions = $this->getPrimaryKeyConditions( $id ); |
98 | 101 | $result = QueryBuild::update( $this->table ); |
99 | - foreach ( $conditions as $field => $value ) |
|
100 | - $result->whereEqual( $field, $value ); |
|
102 | + foreach ( $conditions as $field => $value ) { |
|
103 | + $result->whereEqual( $field, $value ); |
|
104 | + } |
|
101 | 105 | $result->setFieldsByArray( $arrayUpdater ); |
102 | 106 | |
103 | 107 | return $result->execute(); |
@@ -133,8 +137,9 @@ discard block |
||
133 | 137 | */ |
134 | 138 | public function saveOrder( $updates_ord = array() ) |
135 | 139 | { |
136 | - if ( empty( $this->orderField ) ) |
|
137 | - throw new QueryException( 'Order field is not defined' ); |
|
140 | + if ( empty( $this->orderField ) ) { |
|
141 | + throw new QueryException( 'Order field is not defined' ); |
|
142 | + } |
|
138 | 143 | |
139 | 144 | $query = /** @lang text */ |
140 | 145 | "UPDATE `{$this->table}` SET `{$this->orderField}` = CASE `{$this->primary[0]}` \r\n"; |
@@ -155,16 +160,19 @@ discard block |
||
155 | 160 | */ |
156 | 161 | protected function getPrimaryKeyConditions( $id ) |
157 | 162 | { |
158 | - if ( !is_array( $id ) ) |
|
159 | - $id = [ $id ]; |
|
163 | + if ( !is_array( $id ) ) { |
|
164 | + $id = [ $id ]; |
|
165 | + } |
|
160 | 166 | |
161 | - if ( count( $this->primary ) !== count( $id ) ) |
|
162 | - throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
167 | + if ( count( $this->primary ) !== count( $id ) ) { |
|
168 | + throw new QueryException( 'Invalid primary key', QueryException::QUERY_CRUD_INVALID_PRIMARY ); |
|
169 | + } |
|
163 | 170 | |
164 | 171 | $conditions = []; |
165 | 172 | |
166 | - foreach ( $this->primary as $index => $key ) |
|
167 | - $conditions[ $key ] = $id[ $index ]; |
|
173 | + foreach ( $this->primary as $index => $key ) { |
|
174 | + $conditions[ $key ] = $id[ $index ]; |
|
175 | + } |
|
168 | 176 | |
169 | 177 | return $conditions; |
170 | 178 | } |