@@ -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 | |
@@ -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 |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | while ( in_array( $instance, self::$usedInstanceIds ) ) { |
| 133 | 133 | $instance = QueryHelper::random( 7 ); |
| 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 | |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | * @param string $search |
| 242 | 242 | * @return string |
| 243 | 243 | */ |
| 244 | - public function bindParamsExpression( $expression, array $params = [], $search = '?' ) |
|
| 244 | + public function bindParamsExpression( $expression, array $params = [ ], $search = '?' ) |
|
| 245 | 245 | { |
| 246 | 246 | if ( !count( $params ) ) |
| 247 | 247 | return $expression; |
@@ -252,12 +252,12 @@ discard block |
||
| 252 | 252 | $params = array_slice( $params, 0, substr_count( $expression, $search ) ); |
| 253 | 253 | |
| 254 | 254 | $i = 0; |
| 255 | - $arrayReturn = []; |
|
| 255 | + $arrayReturn = [ ]; |
|
| 256 | 256 | $expressionToArray = explode( $search, $expression ); |
| 257 | 257 | |
| 258 | 258 | foreach ( $expressionToArray as $sub ) { |
| 259 | - $arrayReturn[] = $sub; |
|
| 260 | - $arrayReturn[] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : ''; |
|
| 259 | + $arrayReturn[ ] = $sub; |
|
| 260 | + $arrayReturn[ ] = array_key_exists( $i, $params ) ? $this->bindParam( 'exp', $params[ $i ] ) : ''; |
|
| 261 | 261 | $i++; |
| 262 | 262 | } |
| 263 | 263 | |
@@ -42,8 +42,9 @@ discard block |
||
| 42 | 42 | */ |
| 43 | 43 | public function getMasterConnection() |
| 44 | 44 | { |
| 45 | - if ( !is_a( $this->pdoMaster, \PDO::class ) ) |
|
| 46 | - $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() ); |
|
| 45 | + if ( !is_a( $this->pdoMaster, \PDO::class ) ) { |
|
| 46 | + $this->pdoMaster = $this->connect( $this->config->getMasterDataConnect() ); |
|
| 47 | + } |
|
| 47 | 48 | |
| 48 | 49 | return $this->pdoMaster; |
| 49 | 50 | } |
@@ -53,11 +54,13 @@ discard block |
||
| 53 | 54 | */ |
| 54 | 55 | public function getSlaveConnection() |
| 55 | 56 | { |
| 56 | - if ( !$this->config->getReplicationEnable() ) |
|
| 57 | - return $this->getMasterConnection(); |
|
| 57 | + if ( !$this->config->getReplicationEnable() ) { |
|
| 58 | + return $this->getMasterConnection(); |
|
| 59 | + } |
|
| 58 | 60 | |
| 59 | - if ( !is_a( $this->pdoSlave, \PDO::class ) ) |
|
| 60 | - $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() ); |
|
| 61 | + if ( !is_a( $this->pdoSlave, \PDO::class ) ) { |
|
| 62 | + $this->pdoSlave = $this->connect( $this->config->getSlaveDataConnect() ); |
|
| 63 | + } |
|
| 61 | 64 | |
| 62 | 65 | return $this->pdoSlave; |
| 63 | 66 | } |
@@ -70,8 +73,9 @@ discard block |
||
| 70 | 73 | { |
| 71 | 74 | $statement = trim( strtolower( $statement ) ); |
| 72 | 75 | |
| 73 | - if ( $statement === DbService::QUERY_TYPE_SELECT ) |
|
| 74 | - return $this->getSlaveConnection(); |
|
| 76 | + if ( $statement === DbService::QUERY_TYPE_SELECT ) { |
|
| 77 | + return $this->getSlaveConnection(); |
|
| 78 | + } |
|
| 75 | 79 | |
| 76 | 80 | return $this->getMasterConnection(); |
| 77 | 81 | } |
@@ -85,12 +85,10 @@ |
||
| 85 | 85 | $fh = fopen( $log, 'a+' ); |
| 86 | 86 | fwrite( $fh, $messageFormat ); |
| 87 | 87 | fclose( $fh ); |
| 88 | - } |
|
| 89 | - else { |
|
| 88 | + } else { |
|
| 90 | 89 | $this->edit( $log, $messageFormat ); |
| 91 | 90 | } |
| 92 | - } |
|
| 93 | - else { |
|
| 91 | + } else { |
|
| 94 | 92 | if ( mkdir( $this->path, 0777 ) === true ) { |
| 95 | 93 | $this->write( $message ); |
| 96 | 94 | } |
@@ -17,110 +17,110 @@ |
||
| 17 | 17 | trait InsertMultiple |
| 18 | 18 | { |
| 19 | 19 | |
| 20 | - use Objects; |
|
| 20 | + use Objects; |
|
| 21 | 21 | |
| 22 | 22 | |
| 23 | - /** |
|
| 24 | - * @param $fieldsList |
|
| 25 | - * @param array $rowsForInsert |
|
| 26 | - * @return $this |
|
| 27 | - */ |
|
| 28 | - public function fromArray($fieldsList, array $rowsForInsert) |
|
| 29 | - { |
|
| 30 | - $this->setFieldsList($fieldsList); |
|
| 23 | + /** |
|
| 24 | + * @param $fieldsList |
|
| 25 | + * @param array $rowsForInsert |
|
| 26 | + * @return $this |
|
| 27 | + */ |
|
| 28 | + public function fromArray($fieldsList, array $rowsForInsert) |
|
| 29 | + { |
|
| 30 | + $this->setFieldsList($fieldsList); |
|
| 31 | 31 | |
| 32 | - foreach ($rowsForInsert as $row) |
|
| 33 | - $this->addSingleRow($row); |
|
| 32 | + foreach ($rowsForInsert as $row) |
|
| 33 | + $this->addSingleRow($row); |
|
| 34 | 34 | |
| 35 | - return $this; |
|
| 36 | - } |
|
| 35 | + return $this; |
|
| 36 | + } |
|
| 37 | 37 | |
| 38 | 38 | |
| 39 | - /** |
|
| 40 | - * @param $fieldsList |
|
| 41 | - * @param QuerySelect $query |
|
| 42 | - * @return $this |
|
| 43 | - */ |
|
| 44 | - public function fromQuerySelect($fieldsList, QuerySelect $query) |
|
| 45 | - { |
|
| 46 | - $this->setFieldsList($fieldsList); |
|
| 39 | + /** |
|
| 40 | + * @param $fieldsList |
|
| 41 | + * @param QuerySelect $query |
|
| 42 | + * @return $this |
|
| 43 | + */ |
|
| 44 | + public function fromQuerySelect($fieldsList, QuerySelect $query) |
|
| 45 | + { |
|
| 46 | + $this->setFieldsList($fieldsList); |
|
| 47 | 47 | |
| 48 | - foreach ($query->getBindParams() as $key => $value) |
|
| 49 | - $this->queryStructure->setParams($key, $value); |
|
| 48 | + foreach ($query->getBindParams() as $key => $value) |
|
| 49 | + $this->queryStructure->setParams($key, $value); |
|
| 50 | 50 | |
| 51 | - $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
|
| 51 | + $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
|
| 52 | 52 | |
| 53 | - return $this; |
|
| 54 | - } |
|
| 53 | + return $this; |
|
| 54 | + } |
|
| 55 | 55 | |
| 56 | 56 | |
| 57 | - /** |
|
| 58 | - * @param string|array $fieldList |
|
| 59 | - */ |
|
| 60 | - private function setFieldsList($fieldList) |
|
| 61 | - { |
|
| 62 | - if (!is_array($fieldList)) |
|
| 63 | - $fieldList = QueryHelper::explode($fieldList); |
|
| 57 | + /** |
|
| 58 | + * @param string|array $fieldList |
|
| 59 | + */ |
|
| 60 | + private function setFieldsList($fieldList) |
|
| 61 | + { |
|
| 62 | + if (!is_array($fieldList)) |
|
| 63 | + $fieldList = QueryHelper::explode($fieldList); |
|
| 64 | 64 | |
| 65 | - $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
|
| 65 | + $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
|
| 66 | 66 | |
| 67 | - } |
|
| 67 | + } |
|
| 68 | 68 | |
| 69 | - /** |
|
| 70 | - * @param array $rowValues |
|
| 71 | - * @return $this |
|
| 72 | - * @throws QueryException |
|
| 73 | - */ |
|
| 74 | - private function addSingleRow(array $rowValues) |
|
| 75 | - { |
|
| 69 | + /** |
|
| 70 | + * @param array $rowValues |
|
| 71 | + * @return $this |
|
| 72 | + * @throws QueryException |
|
| 73 | + */ |
|
| 74 | + private function addSingleRow(array $rowValues) |
|
| 75 | + { |
|
| 76 | 76 | |
| 77 | - if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | - throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 77 | + if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | + throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 79 | 79 | |
| 80 | - $pdoRowValues = array(); |
|
| 80 | + $pdoRowValues = array(); |
|
| 81 | 81 | |
| 82 | - foreach ($rowValues as $value) |
|
| 83 | - $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 82 | + foreach ($rowValues as $value) |
|
| 83 | + $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 84 | 84 | |
| 85 | - $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
|
| 85 | + $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
|
| 86 | 86 | |
| 87 | - $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString); |
|
| 87 | + $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString); |
|
| 88 | 88 | |
| 89 | - return $this; |
|
| 90 | - } |
|
| 89 | + return $this; |
|
| 90 | + } |
|
| 91 | 91 | |
| 92 | - /** |
|
| 93 | - * @return string |
|
| 94 | - */ |
|
| 95 | - private function getInsertMultipleRowsSyntax() |
|
| 96 | - { |
|
| 97 | - if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 98 | - return $this->getSyntaxWithSelect(); |
|
| 92 | + /** |
|
| 93 | + * @return string |
|
| 94 | + */ |
|
| 95 | + private function getInsertMultipleRowsSyntax() |
|
| 96 | + { |
|
| 97 | + if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 98 | + return $this->getSyntaxWithSelect(); |
|
| 99 | 99 | |
| 100 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 101 | - $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
|
| 100 | + $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 101 | + $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
|
| 102 | 102 | |
| 103 | - return $fields . ' VALUES ' . $values; |
|
| 104 | - } |
|
| 103 | + return $fields . ' VALUES ' . $values; |
|
| 104 | + } |
|
| 105 | 105 | |
| 106 | 106 | |
| 107 | - /** |
|
| 108 | - * @return string |
|
| 109 | - */ |
|
| 110 | - private function getSyntaxWithSelect() |
|
| 111 | - { |
|
| 112 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 107 | + /** |
|
| 108 | + * @return string |
|
| 109 | + */ |
|
| 110 | + private function getSyntaxWithSelect() |
|
| 111 | + { |
|
| 112 | + $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 113 | 113 | |
| 114 | - return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax(); |
|
| 115 | - } |
|
| 114 | + return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax(); |
|
| 115 | + } |
|
| 116 | 116 | |
| 117 | - /** |
|
| 118 | - * @return int |
|
| 119 | - */ |
|
| 120 | - private function getNumberOfFields() |
|
| 121 | - { |
|
| 122 | - return count($this->queryStructure->getElement(QueryStructure::FIELDS)); |
|
| 123 | - } |
|
| 117 | + /** |
|
| 118 | + * @return int |
|
| 119 | + */ |
|
| 120 | + private function getNumberOfFields() |
|
| 121 | + { |
|
| 122 | + return count($this->queryStructure->getElement(QueryStructure::FIELDS)); |
|
| 123 | + } |
|
| 124 | 124 | |
| 125 | 125 | |
| 126 | 126 | } |
| 127 | 127 | \ No newline at end of file |
@@ -25,12 +25,12 @@ discard block |
||
| 25 | 25 | * @param array $rowsForInsert |
| 26 | 26 | * @return $this |
| 27 | 27 | */ |
| 28 | - public function fromArray($fieldsList, array $rowsForInsert) |
|
| 28 | + public function fromArray( $fieldsList, array $rowsForInsert ) |
|
| 29 | 29 | { |
| 30 | - $this->setFieldsList($fieldsList); |
|
| 30 | + $this->setFieldsList( $fieldsList ); |
|
| 31 | 31 | |
| 32 | - foreach ($rowsForInsert as $row) |
|
| 33 | - $this->addSingleRow($row); |
|
| 32 | + foreach ( $rowsForInsert as $row ) |
|
| 33 | + $this->addSingleRow( $row ); |
|
| 34 | 34 | |
| 35 | 35 | return $this; |
| 36 | 36 | } |
@@ -41,14 +41,14 @@ discard block |
||
| 41 | 41 | * @param QuerySelect $query |
| 42 | 42 | * @return $this |
| 43 | 43 | */ |
| 44 | - public function fromQuerySelect($fieldsList, QuerySelect $query) |
|
| 44 | + public function fromQuerySelect( $fieldsList, QuerySelect $query ) |
|
| 45 | 45 | { |
| 46 | - $this->setFieldsList($fieldsList); |
|
| 46 | + $this->setFieldsList( $fieldsList ); |
|
| 47 | 47 | |
| 48 | - foreach ($query->getBindParams() as $key => $value) |
|
| 49 | - $this->queryStructure->setParams($key, $value); |
|
| 48 | + foreach ( $query->getBindParams() as $key => $value ) |
|
| 49 | + $this->queryStructure->setParams( $key, $value ); |
|
| 50 | 50 | |
| 51 | - $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
|
| 51 | + $this->queryStructure->replaceElement( QueryStructure::SET_FIELDS, $query ); |
|
| 52 | 52 | |
| 53 | 53 | return $this; |
| 54 | 54 | } |
@@ -57,12 +57,12 @@ discard block |
||
| 57 | 57 | /** |
| 58 | 58 | * @param string|array $fieldList |
| 59 | 59 | */ |
| 60 | - private function setFieldsList($fieldList) |
|
| 60 | + private function setFieldsList( $fieldList ) |
|
| 61 | 61 | { |
| 62 | - if (!is_array($fieldList)) |
|
| 63 | - $fieldList = QueryHelper::explode($fieldList); |
|
| 62 | + if ( !is_array( $fieldList ) ) |
|
| 63 | + $fieldList = QueryHelper::explode( $fieldList ); |
|
| 64 | 64 | |
| 65 | - $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
|
| 65 | + $this->queryStructure->replaceElement( QueryStructure::FIELDS, $fieldList ); |
|
| 66 | 66 | |
| 67 | 67 | } |
| 68 | 68 | |
@@ -71,20 +71,20 @@ discard block |
||
| 71 | 71 | * @return $this |
| 72 | 72 | * @throws QueryException |
| 73 | 73 | */ |
| 74 | - private function addSingleRow(array $rowValues) |
|
| 74 | + private function addSingleRow( array $rowValues ) |
|
| 75 | 75 | { |
| 76 | 76 | |
| 77 | - if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | - throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 77 | + if ( $this->getNumberOfFields() !== count( $rowValues ) ) |
|
| 78 | + throw new QueryException( 'Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT ); |
|
| 79 | 79 | |
| 80 | 80 | $pdoRowValues = array(); |
| 81 | 81 | |
| 82 | - foreach ($rowValues as $value) |
|
| 83 | - $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 82 | + foreach ( $rowValues as $value ) |
|
| 83 | + $pdoRowValues[ ] = $this->queryStructure->bindParam( 'value', $value ); |
|
| 84 | 84 | |
| 85 | - $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
|
| 85 | + $pdoRowValuesString = '( ' . QueryHelper::implode( $pdoRowValues, ', ' ) . ' )'; |
|
| 86 | 86 | |
| 87 | - $this->queryStructure->setElement(QueryStructure::SET_FIELDS, $pdoRowValuesString); |
|
| 87 | + $this->queryStructure->setElement( QueryStructure::SET_FIELDS, $pdoRowValuesString ); |
|
| 88 | 88 | |
| 89 | 89 | return $this; |
| 90 | 90 | } |
@@ -94,11 +94,11 @@ discard block |
||
| 94 | 94 | */ |
| 95 | 95 | private function getInsertMultipleRowsSyntax() |
| 96 | 96 | { |
| 97 | - if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 97 | + if ( is_a( $this->queryStructure->getElement( QueryStructure::SET_FIELDS ), QuerySelect::class ) ) |
|
| 98 | 98 | return $this->getSyntaxWithSelect(); |
| 99 | 99 | |
| 100 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 101 | - $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
|
| 100 | + $fields = '( ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::FIELDS ), ', ' ) . ' )'; |
|
| 101 | + $values = QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::SET_FIELDS ), ', ' ); |
|
| 102 | 102 | |
| 103 | 103 | return $fields . ' VALUES ' . $values; |
| 104 | 104 | } |
@@ -109,9 +109,9 @@ discard block |
||
| 109 | 109 | */ |
| 110 | 110 | private function getSyntaxWithSelect() |
| 111 | 111 | { |
| 112 | - $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
|
| 112 | + $fields = '( ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::FIELDS ), ', ' ) . ' )'; |
|
| 113 | 113 | |
| 114 | - return $fields . ' ' . $this->queryStructure->getElement(QueryStructure::SET_FIELDS)->getSyntax(); |
|
| 114 | + return $fields . ' ' . $this->queryStructure->getElement( QueryStructure::SET_FIELDS )->getSyntax(); |
|
| 115 | 115 | } |
| 116 | 116 | |
| 117 | 117 | /** |
@@ -119,7 +119,7 @@ discard block |
||
| 119 | 119 | */ |
| 120 | 120 | private function getNumberOfFields() |
| 121 | 121 | { |
| 122 | - return count($this->queryStructure->getElement(QueryStructure::FIELDS)); |
|
| 122 | + return count( $this->queryStructure->getElement( QueryStructure::FIELDS ) ); |
|
| 123 | 123 | } |
| 124 | 124 | |
| 125 | 125 | |
@@ -29,8 +29,9 @@ discard block |
||
| 29 | 29 | { |
| 30 | 30 | $this->setFieldsList($fieldsList); |
| 31 | 31 | |
| 32 | - foreach ($rowsForInsert as $row) |
|
| 33 | - $this->addSingleRow($row); |
|
| 32 | + foreach ($rowsForInsert as $row) { |
|
| 33 | + $this->addSingleRow($row); |
|
| 34 | + } |
|
| 34 | 35 | |
| 35 | 36 | return $this; |
| 36 | 37 | } |
@@ -45,8 +46,9 @@ discard block |
||
| 45 | 46 | { |
| 46 | 47 | $this->setFieldsList($fieldsList); |
| 47 | 48 | |
| 48 | - foreach ($query->getBindParams() as $key => $value) |
|
| 49 | - $this->queryStructure->setParams($key, $value); |
|
| 49 | + foreach ($query->getBindParams() as $key => $value) { |
|
| 50 | + $this->queryStructure->setParams($key, $value); |
|
| 51 | + } |
|
| 50 | 52 | |
| 51 | 53 | $this->queryStructure->replaceElement(QueryStructure::SET_FIELDS, $query); |
| 52 | 54 | |
@@ -59,8 +61,9 @@ discard block |
||
| 59 | 61 | */ |
| 60 | 62 | private function setFieldsList($fieldList) |
| 61 | 63 | { |
| 62 | - if (!is_array($fieldList)) |
|
| 63 | - $fieldList = QueryHelper::explode($fieldList); |
|
| 64 | + if (!is_array($fieldList)) { |
|
| 65 | + $fieldList = QueryHelper::explode($fieldList); |
|
| 66 | + } |
|
| 64 | 67 | |
| 65 | 68 | $this->queryStructure->replaceElement(QueryStructure::FIELDS, $fieldList); |
| 66 | 69 | |
@@ -74,13 +77,15 @@ discard block |
||
| 74 | 77 | private function addSingleRow(array $rowValues) |
| 75 | 78 | { |
| 76 | 79 | |
| 77 | - if ($this->getNumberOfFields() !== count($rowValues)) |
|
| 78 | - throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 80 | + if ($this->getNumberOfFields() !== count($rowValues)) { |
|
| 81 | + throw new QueryException('Ivalid number of fields.', QueryException::QUERY_ERROR_INVALID_FIELDS_COUNT); |
|
| 82 | + } |
|
| 79 | 83 | |
| 80 | 84 | $pdoRowValues = array(); |
| 81 | 85 | |
| 82 | - foreach ($rowValues as $value) |
|
| 83 | - $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 86 | + foreach ($rowValues as $value) { |
|
| 87 | + $pdoRowValues[] = $this->queryStructure->bindParam('value', $value); |
|
| 88 | + } |
|
| 84 | 89 | |
| 85 | 90 | $pdoRowValuesString = '( ' . QueryHelper::implode($pdoRowValues, ', ') . ' )'; |
| 86 | 91 | |
@@ -94,8 +99,9 @@ discard block |
||
| 94 | 99 | */ |
| 95 | 100 | private function getInsertMultipleRowsSyntax() |
| 96 | 101 | { |
| 97 | - if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) |
|
| 98 | - return $this->getSyntaxWithSelect(); |
|
| 102 | + if (is_a($this->queryStructure->getElement(QueryStructure::SET_FIELDS), QuerySelect::class)) { |
|
| 103 | + return $this->getSyntaxWithSelect(); |
|
| 104 | + } |
|
| 99 | 105 | |
| 100 | 106 | $fields = '( ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::FIELDS), ', ') . ' )'; |
| 101 | 107 | $values = QueryHelper::implode($this->queryStructure->getElement(QueryStructure::SET_FIELDS), ', '); |
@@ -14,61 +14,61 @@ |
||
| 14 | 14 | |
| 15 | 15 | trait SelectFields |
| 16 | 16 | { |
| 17 | - use Objects; |
|
| 17 | + use Objects; |
|
| 18 | 18 | |
| 19 | 19 | |
| 20 | - /** |
|
| 21 | - * @param string|array $fields |
|
| 22 | - * @return $this |
|
| 23 | - * @throws QueryException |
|
| 24 | - */ |
|
| 25 | - public function fields($fields) |
|
| 26 | - { |
|
| 20 | + /** |
|
| 21 | + * @param string|array $fields |
|
| 22 | + * @return $this |
|
| 23 | + * @throws QueryException |
|
| 24 | + */ |
|
| 25 | + public function fields($fields) |
|
| 26 | + { |
|
| 27 | 27 | |
| 28 | - switch (gettype($fields)) { |
|
| 29 | - case QueryStructure::ELEMENT_TYPE_ARRAY: |
|
| 28 | + switch (gettype($fields)) { |
|
| 29 | + case QueryStructure::ELEMENT_TYPE_ARRAY: |
|
| 30 | 30 | |
| 31 | - $fields = $this->prepareArrayFields($fields); |
|
| 31 | + $fields = $this->prepareArrayFields($fields); |
|
| 32 | 32 | |
| 33 | - if (count($fields)) |
|
| 34 | - $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 36 | - break; |
|
| 33 | + if (count($fields)) |
|
| 34 | + $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | + $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 36 | + break; |
|
| 37 | 37 | |
| 38 | - case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 38 | + case QueryStructure::ELEMENT_TYPE_STRING: |
|
| 39 | 39 | |
| 40 | - $fields = trim($fields); |
|
| 41 | - if ('' !== $fields) |
|
| 42 | - $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 44 | - break; |
|
| 40 | + $fields = trim($fields); |
|
| 41 | + if ('' !== $fields) |
|
| 42 | + $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | + $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 44 | + break; |
|
| 45 | 45 | |
| 46 | - default: |
|
| 47 | - throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY); |
|
| 46 | + default: |
|
| 47 | + throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY); |
|
| 48 | 48 | |
| 49 | - } |
|
| 49 | + } |
|
| 50 | 50 | |
| 51 | - return $this; |
|
| 52 | - } |
|
| 51 | + return $this; |
|
| 52 | + } |
|
| 53 | 53 | |
| 54 | - /** |
|
| 55 | - * @param array $fieldsArray |
|
| 56 | - * @return array |
|
| 57 | - * @throws QueryException |
|
| 58 | - */ |
|
| 59 | - private function prepareArrayFields($fieldsArray = array()) |
|
| 60 | - { |
|
| 61 | - $prepareArray = []; |
|
| 54 | + /** |
|
| 55 | + * @param array $fieldsArray |
|
| 56 | + * @return array |
|
| 57 | + * @throws QueryException |
|
| 58 | + */ |
|
| 59 | + private function prepareArrayFields($fieldsArray = array()) |
|
| 60 | + { |
|
| 61 | + $prepareArray = []; |
|
| 62 | 62 | |
| 63 | - foreach ($fieldsArray as $field) { |
|
| 64 | - if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | - throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 63 | + foreach ($fieldsArray as $field) { |
|
| 64 | + if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | + throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 66 | 66 | |
| 67 | - if ('' !== trim($field)) |
|
| 68 | - $prepareArray[] = trim($field); |
|
| 69 | - } |
|
| 67 | + if ('' !== trim($field)) |
|
| 68 | + $prepareArray[] = trim($field); |
|
| 69 | + } |
|
| 70 | 70 | |
| 71 | - return $prepareArray; |
|
| 72 | - } |
|
| 71 | + return $prepareArray; |
|
| 72 | + } |
|
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -22,29 +22,29 @@ discard block |
||
| 22 | 22 | * @return $this |
| 23 | 23 | * @throws QueryException |
| 24 | 24 | */ |
| 25 | - public function fields($fields) |
|
| 25 | + public function fields( $fields ) |
|
| 26 | 26 | { |
| 27 | 27 | |
| 28 | - switch (gettype($fields)) { |
|
| 28 | + switch ( gettype( $fields ) ) { |
|
| 29 | 29 | case QueryStructure::ELEMENT_TYPE_ARRAY: |
| 30 | 30 | |
| 31 | - $fields = $this->prepareArrayFields($fields); |
|
| 31 | + $fields = $this->prepareArrayFields( $fields ); |
|
| 32 | 32 | |
| 33 | - if (count($fields)) |
|
| 34 | - $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 33 | + if ( count( $fields ) ) |
|
| 34 | + $this->queryStructure->setElement( QueryStructure::FIELDS, implode( ', ', $fields ) ); else |
|
| 35 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
| 36 | 36 | break; |
| 37 | 37 | |
| 38 | 38 | case QueryStructure::ELEMENT_TYPE_STRING: |
| 39 | 39 | |
| 40 | - $fields = trim($fields); |
|
| 41 | - if ('' !== $fields) |
|
| 42 | - $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 40 | + $fields = trim( $fields ); |
|
| 41 | + if ( '' !== $fields ) |
|
| 42 | + $this->queryStructure->setElement( QueryStructure::FIELDS, $fields ); else |
|
| 43 | + $this->queryStructure->setElement( QueryStructure::FIELDS, '*' ); |
|
| 44 | 44 | break; |
| 45 | 45 | |
| 46 | 46 | default: |
| 47 | - throw new QueryException('Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY); |
|
| 47 | + throw new QueryException( 'Invalid fields parameter type', QueryException::QUERY_ERROR_WHERE_INVALID_PARAM_ARRAY ); |
|
| 48 | 48 | |
| 49 | 49 | } |
| 50 | 50 | |
@@ -56,16 +56,16 @@ discard block |
||
| 56 | 56 | * @return array |
| 57 | 57 | * @throws QueryException |
| 58 | 58 | */ |
| 59 | - private function prepareArrayFields($fieldsArray = array()) |
|
| 59 | + private function prepareArrayFields( $fieldsArray = array() ) |
|
| 60 | 60 | { |
| 61 | - $prepareArray = []; |
|
| 61 | + $prepareArray = [ ]; |
|
| 62 | 62 | |
| 63 | - foreach ($fieldsArray as $field) { |
|
| 64 | - if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | - throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 63 | + foreach ( $fieldsArray as $field ) { |
|
| 64 | + if ( gettype( $field ) !== QueryStructure::ELEMENT_TYPE_STRING ) |
|
| 65 | + throw new QueryException( 'Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD ); |
|
| 66 | 66 | |
| 67 | - if ('' !== trim($field)) |
|
| 68 | - $prepareArray[] = trim($field); |
|
| 67 | + if ( '' !== trim( $field ) ) |
|
| 68 | + $prepareArray[ ] = trim( $field ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | return $prepareArray; |
@@ -30,17 +30,21 @@ discard block |
||
| 30 | 30 | |
| 31 | 31 | $fields = $this->prepareArrayFields($fields); |
| 32 | 32 | |
| 33 | - if (count($fields)) |
|
| 34 | - $this->queryStructure->setElement(QueryStructure::FIELDS, implode(', ', $fields)); else |
|
| 35 | - $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 | + } |
|
| 36 | 38 | break; |
| 37 | 39 | |
| 38 | 40 | case QueryStructure::ELEMENT_TYPE_STRING: |
| 39 | 41 | |
| 40 | 42 | $fields = trim($fields); |
| 41 | - if ('' !== $fields) |
|
| 42 | - $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); else |
|
| 43 | - $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 43 | + if ('' !== $fields) { |
|
| 44 | + $this->queryStructure->setElement(QueryStructure::FIELDS, $fields); |
|
| 45 | + } else { |
|
| 46 | + $this->queryStructure->setElement(QueryStructure::FIELDS, '*'); |
|
| 47 | + } |
|
| 44 | 48 | break; |
| 45 | 49 | |
| 46 | 50 | default: |
@@ -61,11 +65,13 @@ discard block |
||
| 61 | 65 | $prepareArray = []; |
| 62 | 66 | |
| 63 | 67 | foreach ($fieldsArray as $field) { |
| 64 | - if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) |
|
| 65 | - throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 68 | + if (gettype($field) !== QueryStructure::ELEMENT_TYPE_STRING) { |
|
| 69 | + throw new QueryException('Invalid select field type!', QueryException::QUERY_ERROR_SELECT_INVALID_FIELD); |
|
| 70 | + } |
|
| 66 | 71 | |
| 67 | - if ('' !== trim($field)) |
|
| 68 | - $prepareArray[] = trim($field); |
|
| 72 | + if ('' !== trim($field)) { |
|
| 73 | + $prepareArray[] = trim($field); |
|
| 74 | + } |
|
| 69 | 75 | } |
| 70 | 76 | |
| 71 | 77 | return $prepareArray; |
@@ -15,68 +15,68 @@ |
||
| 15 | 15 | trait GroupBy |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - use Objects; |
|
| 18 | + use Objects; |
|
| 19 | 19 | |
| 20 | 20 | |
| 21 | - /** |
|
| 22 | - * @param $column |
|
| 23 | - * @param array $allowedColumns |
|
| 24 | - * @return $this |
|
| 25 | - * @throws QueryException |
|
| 26 | - */ |
|
| 27 | - public function groupBy($column, array $allowedColumns = []) |
|
| 28 | - { |
|
| 29 | - $column = trim($column); |
|
| 21 | + /** |
|
| 22 | + * @param $column |
|
| 23 | + * @param array $allowedColumns |
|
| 24 | + * @return $this |
|
| 25 | + * @throws QueryException |
|
| 26 | + */ |
|
| 27 | + public function groupBy($column, array $allowedColumns = []) |
|
| 28 | + { |
|
| 29 | + $column = trim($column); |
|
| 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 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column); |
|
| 34 | + $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column); |
|
| 35 | 35 | |
| 36 | - return $this; |
|
| 37 | - } |
|
| 36 | + return $this; |
|
| 37 | + } |
|
| 38 | 38 | |
| 39 | 39 | |
| 40 | - /** |
|
| 41 | - * @param $column |
|
| 42 | - * @param array $allowedColumns |
|
| 43 | - * @return $this |
|
| 44 | - * @throws QueryException |
|
| 45 | - */ |
|
| 46 | - public function groupByDesc($column, array $allowedColumns = []) |
|
| 47 | - { |
|
| 48 | - $column = trim($column); |
|
| 40 | + /** |
|
| 41 | + * @param $column |
|
| 42 | + * @param array $allowedColumns |
|
| 43 | + * @return $this |
|
| 44 | + * @throws QueryException |
|
| 45 | + */ |
|
| 46 | + public function groupByDesc($column, array $allowedColumns = []) |
|
| 47 | + { |
|
| 48 | + $column = trim($column); |
|
| 49 | 49 | |
| 50 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | - throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 50 | + if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | + throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 52 | 52 | |
| 53 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC'); |
|
| 53 | + $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC'); |
|
| 54 | 54 | |
| 55 | - return $this; |
|
| 56 | - } |
|
| 55 | + return $this; |
|
| 56 | + } |
|
| 57 | 57 | |
| 58 | 58 | |
| 59 | - /** |
|
| 60 | - * @param $expression |
|
| 61 | - * @return $this |
|
| 62 | - */ |
|
| 63 | - public function groupByExpression($expression) |
|
| 64 | - { |
|
| 65 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression); |
|
| 59 | + /** |
|
| 60 | + * @param $expression |
|
| 61 | + * @return $this |
|
| 62 | + */ |
|
| 63 | + public function groupByExpression($expression) |
|
| 64 | + { |
|
| 65 | + $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression); |
|
| 66 | 66 | |
| 67 | - return $this; |
|
| 68 | - } |
|
| 67 | + return $this; |
|
| 68 | + } |
|
| 69 | 69 | |
| 70 | 70 | |
| 71 | - /** |
|
| 72 | - * @return string |
|
| 73 | - */ |
|
| 74 | - private function getGroupBySyntax() |
|
| 75 | - { |
|
| 76 | - if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | - return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 71 | + /** |
|
| 72 | + * @return string |
|
| 73 | + */ |
|
| 74 | + private function getGroupBySyntax() |
|
| 75 | + { |
|
| 76 | + if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | + return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 78 | 78 | |
| 79 | - return ''; |
|
| 80 | - } |
|
| 79 | + return ''; |
|
| 80 | + } |
|
| 81 | 81 | |
| 82 | 82 | } |
| 83 | 83 | \ No newline at end of file |
@@ -24,14 +24,14 @@ discard block |
||
| 24 | 24 | * @return $this |
| 25 | 25 | * @throws QueryException |
| 26 | 26 | */ |
| 27 | - public function groupBy($column, array $allowedColumns = []) |
|
| 27 | + public function groupBy( $column, array $allowedColumns = [ ] ) |
|
| 28 | 28 | { |
| 29 | - $column = trim($column); |
|
| 29 | + $column = trim( $column ); |
|
| 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 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column); |
|
| 34 | + $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column ); |
|
| 35 | 35 | |
| 36 | 36 | return $this; |
| 37 | 37 | } |
@@ -43,14 +43,14 @@ discard block |
||
| 43 | 43 | * @return $this |
| 44 | 44 | * @throws QueryException |
| 45 | 45 | */ |
| 46 | - public function groupByDesc($column, array $allowedColumns = []) |
|
| 46 | + public function groupByDesc( $column, array $allowedColumns = [ ] ) |
|
| 47 | 47 | { |
| 48 | - $column = trim($column); |
|
| 48 | + $column = trim( $column ); |
|
| 49 | 49 | |
| 50 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | - throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 50 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) |
|
| 51 | + throw new QueryException( 'Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 52 | 52 | |
| 53 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC'); |
|
| 53 | + $this->queryStructure->setElement( QueryStructure::GROUP_BY, $column . ' DESC' ); |
|
| 54 | 54 | |
| 55 | 55 | return $this; |
| 56 | 56 | } |
@@ -60,9 +60,9 @@ discard block |
||
| 60 | 60 | * @param $expression |
| 61 | 61 | * @return $this |
| 62 | 62 | */ |
| 63 | - public function groupByExpression($expression) |
|
| 63 | + public function groupByExpression( $expression ) |
|
| 64 | 64 | { |
| 65 | - $this->queryStructure->setElement(QueryStructure::GROUP_BY, $expression); |
|
| 65 | + $this->queryStructure->setElement( QueryStructure::GROUP_BY, $expression ); |
|
| 66 | 66 | |
| 67 | 67 | return $this; |
| 68 | 68 | } |
@@ -73,8 +73,8 @@ discard block |
||
| 73 | 73 | */ |
| 74 | 74 | private function getGroupBySyntax() |
| 75 | 75 | { |
| 76 | - if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | - return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 76 | + if ( count( $this->queryStructure->getElement( QueryStructure::GROUP_BY ) ) ) |
|
| 77 | + return 'GROUP BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::GROUP_BY ), ', ' ); |
|
| 78 | 78 | |
| 79 | 79 | return ''; |
| 80 | 80 | } |
@@ -28,8 +28,9 @@ discard block |
||
| 28 | 28 | { |
| 29 | 29 | $column = trim($column); |
| 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 | $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column); |
| 35 | 36 | |
@@ -47,8 +48,9 @@ discard block |
||
| 47 | 48 | { |
| 48 | 49 | $column = trim($column); |
| 49 | 50 | |
| 50 | - if (!$this->validateColumn($column, $allowedColumns)) |
|
| 51 | - throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 51 | + if (!$this->validateColumn($column, $allowedColumns)) { |
|
| 52 | + throw new QueryException('Invalid column name in GROUP BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $this->queryStructure->setElement(QueryStructure::GROUP_BY, $column . ' DESC'); |
| 54 | 56 | |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | */ |
| 74 | 76 | private function getGroupBySyntax() |
| 75 | 77 | { |
| 76 | - if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) |
|
| 77 | - return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 78 | + if (count($this->queryStructure->getElement(QueryStructure::GROUP_BY))) { |
|
| 79 | + return 'GROUP BY ' . QueryHelper::implode($this->queryStructure->getElement(QueryStructure::GROUP_BY), ', '); |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | return ''; |
| 80 | 83 | } |
@@ -16,40 +16,40 @@ |
||
| 16 | 16 | trait Replacement |
| 17 | 17 | { |
| 18 | 18 | |
| 19 | - use Objects; |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @param $syntax |
|
| 23 | - * @param int $withReplacement |
|
| 24 | - * @return mixed|string |
|
| 25 | - */ |
|
| 26 | - private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE) |
|
| 27 | - { |
|
| 28 | - $syntax = QueryHelper::clearMultipleSpaces($syntax); |
|
| 29 | - |
|
| 30 | - if (!$withReplacement) |
|
| 31 | - return $syntax; |
|
| 32 | - |
|
| 33 | - return $this->replaceValues($syntax); |
|
| 34 | - } |
|
| 35 | - |
|
| 36 | - /** |
|
| 37 | - * @param $syntax |
|
| 38 | - * @return string |
|
| 39 | - */ |
|
| 40 | - private function replaceValues($syntax) |
|
| 41 | - { |
|
| 42 | - $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS); |
|
| 43 | - $search = array(); |
|
| 44 | - $replace = array(); |
|
| 45 | - foreach ($bindParams as $key => $value) { |
|
| 46 | - $search[] = ':' . $key; |
|
| 47 | - $replace[] = DbConnect::getInstance()->quote($value); |
|
| 48 | - } |
|
| 49 | - $syntax = str_ireplace($search, $replace, $syntax); |
|
| 50 | - |
|
| 51 | - return $syntax; |
|
| 52 | - |
|
| 53 | - } |
|
| 19 | + use Objects; |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @param $syntax |
|
| 23 | + * @param int $withReplacement |
|
| 24 | + * @return mixed|string |
|
| 25 | + */ |
|
| 26 | + private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE) |
|
| 27 | + { |
|
| 28 | + $syntax = QueryHelper::clearMultipleSpaces($syntax); |
|
| 29 | + |
|
| 30 | + if (!$withReplacement) |
|
| 31 | + return $syntax; |
|
| 32 | + |
|
| 33 | + return $this->replaceValues($syntax); |
|
| 34 | + } |
|
| 35 | + |
|
| 36 | + /** |
|
| 37 | + * @param $syntax |
|
| 38 | + * @return string |
|
| 39 | + */ |
|
| 40 | + private function replaceValues($syntax) |
|
| 41 | + { |
|
| 42 | + $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS); |
|
| 43 | + $search = array(); |
|
| 44 | + $replace = array(); |
|
| 45 | + foreach ($bindParams as $key => $value) { |
|
| 46 | + $search[] = ':' . $key; |
|
| 47 | + $replace[] = DbConnect::getInstance()->quote($value); |
|
| 48 | + } |
|
| 49 | + $syntax = str_ireplace($search, $replace, $syntax); |
|
| 50 | + |
|
| 51 | + return $syntax; |
|
| 52 | + |
|
| 53 | + } |
|
| 54 | 54 | |
| 55 | 55 | } |
| 56 | 56 | \ No newline at end of file |
@@ -23,30 +23,30 @@ |
||
| 23 | 23 | * @param int $withReplacement |
| 24 | 24 | * @return mixed|string |
| 25 | 25 | */ |
| 26 | - private function getSyntaxReplace($syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE) |
|
| 26 | + private function getSyntaxReplace( $syntax, $withReplacement = QueryStatementInterface::REPLACEMENT_NONE ) |
|
| 27 | 27 | { |
| 28 | - $syntax = QueryHelper::clearMultipleSpaces($syntax); |
|
| 28 | + $syntax = QueryHelper::clearMultipleSpaces( $syntax ); |
|
| 29 | 29 | |
| 30 | - if (!$withReplacement) |
|
| 30 | + if ( !$withReplacement ) |
|
| 31 | 31 | return $syntax; |
| 32 | 32 | |
| 33 | - return $this->replaceValues($syntax); |
|
| 33 | + return $this->replaceValues( $syntax ); |
|
| 34 | 34 | } |
| 35 | 35 | |
| 36 | 36 | /** |
| 37 | 37 | * @param $syntax |
| 38 | 38 | * @return string |
| 39 | 39 | */ |
| 40 | - private function replaceValues($syntax) |
|
| 40 | + private function replaceValues( $syntax ) |
|
| 41 | 41 | { |
| 42 | - $bindParams = $this->queryStructure->getElement(QueryStructure::BIND_PARAMS); |
|
| 42 | + $bindParams = $this->queryStructure->getElement( QueryStructure::BIND_PARAMS ); |
|
| 43 | 43 | $search = array(); |
| 44 | 44 | $replace = array(); |
| 45 | - foreach ($bindParams as $key => $value) { |
|
| 46 | - $search[] = ':' . $key; |
|
| 47 | - $replace[] = DbConnect::getInstance()->quote($value); |
|
| 45 | + foreach ( $bindParams as $key => $value ) { |
|
| 46 | + $search[ ] = ':' . $key; |
|
| 47 | + $replace[ ] = DbConnect::getInstance()->quote( $value ); |
|
| 48 | 48 | } |
| 49 | - $syntax = str_ireplace($search, $replace, $syntax); |
|
| 49 | + $syntax = str_ireplace( $search, $replace, $syntax ); |
|
| 50 | 50 | |
| 51 | 51 | return $syntax; |
| 52 | 52 | |
@@ -27,8 +27,9 @@ |
||
| 27 | 27 | { |
| 28 | 28 | $syntax = QueryHelper::clearMultipleSpaces($syntax); |
| 29 | 29 | |
| 30 | - if (!$withReplacement) |
|
| 31 | - return $syntax; |
|
| 30 | + if (!$withReplacement) { |
|
| 31 | + return $syntax; |
|
| 32 | + } |
|
| 32 | 33 | |
| 33 | 34 | return $this->replaceValues($syntax); |
| 34 | 35 | } |
@@ -15,60 +15,60 @@ |
||
| 15 | 15 | trait Distinct |
| 16 | 16 | { |
| 17 | 17 | |
| 18 | - use Objects; |
|
| 19 | - |
|
| 20 | - |
|
| 21 | - /** |
|
| 22 | - * @return $this |
|
| 23 | - */ |
|
| 24 | - public function all() |
|
| 25 | - { |
|
| 26 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); |
|
| 27 | - |
|
| 28 | - return $this; |
|
| 29 | - } |
|
| 30 | - |
|
| 31 | - /** |
|
| 32 | - * @return $this |
|
| 33 | - */ |
|
| 34 | - public function distinct() |
|
| 35 | - { |
|
| 36 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 1); |
|
| 37 | - |
|
| 38 | - return $this; |
|
| 39 | - } |
|
| 40 | - |
|
| 41 | - /** |
|
| 42 | - * @return $this |
|
| 43 | - */ |
|
| 44 | - public function distinctRow() |
|
| 45 | - { |
|
| 46 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 2); |
|
| 47 | - |
|
| 48 | - return $this; |
|
| 49 | - } |
|
| 50 | - |
|
| 51 | - |
|
| 52 | - /** |
|
| 53 | - * @return string |
|
| 54 | - * @throws QueryException |
|
| 55 | - */ |
|
| 56 | - private function getDistinctSyntax() |
|
| 57 | - { |
|
| 58 | - $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT); |
|
| 59 | - |
|
| 60 | - switch ($useDistinct) { |
|
| 61 | - case 0: |
|
| 62 | - return ''; |
|
| 63 | - case 1: |
|
| 64 | - return 'DISTINCT'; |
|
| 65 | - case 2: |
|
| 66 | - return 'DISTINCTROW'; |
|
| 67 | - default: |
|
| 68 | - throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT); |
|
| 69 | - } |
|
| 70 | - |
|
| 71 | - } |
|
| 18 | + use Objects; |
|
| 19 | + |
|
| 20 | + |
|
| 21 | + /** |
|
| 22 | + * @return $this |
|
| 23 | + */ |
|
| 24 | + public function all() |
|
| 25 | + { |
|
| 26 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); |
|
| 27 | + |
|
| 28 | + return $this; |
|
| 29 | + } |
|
| 30 | + |
|
| 31 | + /** |
|
| 32 | + * @return $this |
|
| 33 | + */ |
|
| 34 | + public function distinct() |
|
| 35 | + { |
|
| 36 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 1); |
|
| 37 | + |
|
| 38 | + return $this; |
|
| 39 | + } |
|
| 40 | + |
|
| 41 | + /** |
|
| 42 | + * @return $this |
|
| 43 | + */ |
|
| 44 | + public function distinctRow() |
|
| 45 | + { |
|
| 46 | + $this->queryStructure->setElement(QueryStructure::DISTINCT, 2); |
|
| 47 | + |
|
| 48 | + return $this; |
|
| 49 | + } |
|
| 50 | + |
|
| 51 | + |
|
| 52 | + /** |
|
| 53 | + * @return string |
|
| 54 | + * @throws QueryException |
|
| 55 | + */ |
|
| 56 | + private function getDistinctSyntax() |
|
| 57 | + { |
|
| 58 | + $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT); |
|
| 59 | + |
|
| 60 | + switch ($useDistinct) { |
|
| 61 | + case 0: |
|
| 62 | + return ''; |
|
| 63 | + case 1: |
|
| 64 | + return 'DISTINCT'; |
|
| 65 | + case 2: |
|
| 66 | + return 'DISTINCTROW'; |
|
| 67 | + default: |
|
| 68 | + throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT); |
|
| 69 | + } |
|
| 70 | + |
|
| 71 | + } |
|
| 72 | 72 | |
| 73 | 73 | |
| 74 | 74 | } |
| 75 | 75 | \ No newline at end of file |
@@ -23,7 +23,7 @@ discard block |
||
| 23 | 23 | */ |
| 24 | 24 | public function all() |
| 25 | 25 | { |
| 26 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); |
|
| 26 | + $this->queryStructure->setElement( QueryStructure::DISTINCT, 0 ); |
|
| 27 | 27 | |
| 28 | 28 | return $this; |
| 29 | 29 | } |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | */ |
| 34 | 34 | public function distinct() |
| 35 | 35 | { |
| 36 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 1); |
|
| 36 | + $this->queryStructure->setElement( QueryStructure::DISTINCT, 1 ); |
|
| 37 | 37 | |
| 38 | 38 | return $this; |
| 39 | 39 | } |
@@ -43,7 +43,7 @@ discard block |
||
| 43 | 43 | */ |
| 44 | 44 | public function distinctRow() |
| 45 | 45 | { |
| 46 | - $this->queryStructure->setElement(QueryStructure::DISTINCT, 2); |
|
| 46 | + $this->queryStructure->setElement( QueryStructure::DISTINCT, 2 ); |
|
| 47 | 47 | |
| 48 | 48 | return $this; |
| 49 | 49 | } |
@@ -55,9 +55,9 @@ discard block |
||
| 55 | 55 | */ |
| 56 | 56 | private function getDistinctSyntax() |
| 57 | 57 | { |
| 58 | - $useDistinct = $this->queryStructure->getElement(QueryStructure::DISTINCT); |
|
| 58 | + $useDistinct = $this->queryStructure->getElement( QueryStructure::DISTINCT ); |
|
| 59 | 59 | |
| 60 | - switch ($useDistinct) { |
|
| 60 | + switch ( $useDistinct ) { |
|
| 61 | 61 | case 0: |
| 62 | 62 | return ''; |
| 63 | 63 | case 1: |
@@ -65,7 +65,7 @@ discard block |
||
| 65 | 65 | case 2: |
| 66 | 66 | return 'DISTINCTROW'; |
| 67 | 67 | default: |
| 68 | - throw new QueryException('Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT); |
|
| 68 | + throw new QueryException( 'Invalid distinct type', QueryException::QUERY_ERROR_INVALID_DISTINCT ); |
|
| 69 | 69 | } |
| 70 | 70 | |
| 71 | 71 | } |
@@ -14,16 +14,16 @@ |
||
| 14 | 14 | trait LowPriority |
| 15 | 15 | { |
| 16 | 16 | |
| 17 | - use Objects; |
|
| 17 | + use Objects; |
|
| 18 | 18 | |
| 19 | - /** |
|
| 20 | - * @return $this |
|
| 21 | - */ |
|
| 22 | - public function lowPriority() |
|
| 23 | - { |
|
| 24 | - $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY'); |
|
| 19 | + /** |
|
| 20 | + * @return $this |
|
| 21 | + */ |
|
| 22 | + public function lowPriority() |
|
| 23 | + { |
|
| 24 | + $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY'); |
|
| 25 | 25 | |
| 26 | - return $this; |
|
| 27 | - } |
|
| 26 | + return $this; |
|
| 27 | + } |
|
| 28 | 28 | |
| 29 | 29 | } |
| 30 | 30 | \ No newline at end of file |
@@ -21,7 +21,7 @@ |
||
| 21 | 21 | */ |
| 22 | 22 | public function lowPriority() |
| 23 | 23 | { |
| 24 | - $this->queryStructure->setElement(QueryStructure::PRIORITY, 'LOW_PRIORITY'); |
|
| 24 | + $this->queryStructure->setElement( QueryStructure::PRIORITY, 'LOW_PRIORITY' ); |
|
| 25 | 25 | |
| 26 | 26 | return $this; |
| 27 | 27 | } |