@@ -28,11 +28,13 @@ 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 | - if ($limit == 0) |
|
| 35 | - throw new QueryException('Invalid Limit zero', QueryException::QUERY_ERROR_INVALID_LIMIT_ZERO); |
|
| 35 | + if ($limit == 0) { |
|
| 36 | + throw new QueryException('Invalid Limit zero', QueryException::QUERY_ERROR_INVALID_LIMIT_ZERO); |
|
| 37 | + } |
|
| 36 | 38 | |
| 37 | 39 | if (is_null($offset)) { |
| 38 | 40 | $this->queryStructure->setElement(QueryStructure::LIMIT, $limit); |
@@ -42,8 +44,9 @@ discard block |
||
| 42 | 44 | |
| 43 | 45 | $offset = trim($offset); |
| 44 | 46 | |
| 45 | - if (!QueryHelper::isInteger($offset)) |
|
| 46 | - throw new QueryException('Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET); |
|
| 47 | + if (!QueryHelper::isInteger($offset)) { |
|
| 48 | + throw new QueryException('Invalid Limit offset', QueryException::QUERY_ERROR_INVALID_LIMIT_OFFSET); |
|
| 49 | + } |
|
| 47 | 50 | |
| 48 | 51 | $this->queryStructure->setElement(QueryStructure::LIMIT, $offset . ',' . $limit); |
| 49 | 52 | |
@@ -52,8 +55,9 @@ discard block |
||
| 52 | 55 | |
| 53 | 56 | private function getLimitSyntax() |
| 54 | 57 | { |
| 55 | - if (!$this->queryStructure->getElement(QueryStructure::LIMIT)) |
|
| 56 | - return ''; |
|
| 58 | + if (!$this->queryStructure->getElement(QueryStructure::LIMIT)) { |
|
| 59 | + return ''; |
|
| 60 | + } |
|
| 57 | 61 | |
| 58 | 62 | return 'LIMIT ' . $this->queryStructure->getElement(QueryStructure::LIMIT); |
| 59 | 63 | } |
@@ -16,11 +16,13 @@ |
||
| 16 | 16 | |
| 17 | 17 | protected function validateColumn($columnName, array $allowed) |
| 18 | 18 | { |
| 19 | - if (is_integer($columnName)) |
|
| 20 | - return true; |
|
| 19 | + if (is_integer($columnName)) { |
|
| 20 | + return true; |
|
| 21 | + } |
|
| 21 | 22 | |
| 22 | - if (!count($allowed)) |
|
| 23 | - return true; |
|
| 23 | + if (!count($allowed)) { |
|
| 24 | + return true; |
|
| 25 | + } |
|
| 24 | 26 | |
| 25 | 27 | return false; |
| 26 | 28 | } |
@@ -55,8 +55,9 @@ discard block |
||
| 55 | 55 | $this->queryStructure->setElement(QueryStructure::TABLE, $tableName); |
| 56 | 56 | |
| 57 | 57 | $tableSelectParams = $table->getBindParams(); |
| 58 | - foreach ($tableSelectParams as $key => $value) |
|
| 59 | - $this->queryStructure->setParams($key, $value); |
|
| 58 | + foreach ($tableSelectParams as $key => $value) { |
|
| 59 | + $this->queryStructure->setParams($key, $value); |
|
| 60 | + } |
|
| 60 | 61 | |
| 61 | 62 | } |
| 62 | 63 | } |
@@ -107,8 +108,9 @@ discard block |
||
| 107 | 108 | $this->queryStructure->setElement(QueryStructure::DISTINCT, 0); //??? |
| 108 | 109 | } |
| 109 | 110 | |
| 110 | - if ($this->queryStructure->getElement(QueryStructure::FIRST)) |
|
| 111 | - $this->queryStructure->setElement(QueryStructure::LIMIT, 1); |
|
| 111 | + if ($this->queryStructure->getElement(QueryStructure::FIRST)) { |
|
| 112 | + $this->queryStructure->setElement(QueryStructure::LIMIT, 1); |
|
| 113 | + } |
|
| 112 | 114 | |
| 113 | 115 | $syntax = array(); |
| 114 | 116 | |
@@ -190,8 +192,9 @@ discard block |
||
| 190 | 192 | return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
| 191 | 193 | break; |
| 192 | 194 | case $this->queryStructure->getElement(QueryStructure::FIRST): |
| 193 | - if ($this->queryStructure->getElement(QueryStructure::COLUMN)) |
|
| 194 | - return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
| 195 | + if ($this->queryStructure->getElement(QueryStructure::COLUMN)) { |
|
| 196 | + return DbService::getInstance()->single($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
|
| 197 | + } |
|
| 195 | 198 | |
| 196 | 199 | return DbService::getInstance()->row($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
| 197 | 200 | break; |
@@ -106,8 +106,9 @@ |
||
| 106 | 106 | */ |
| 107 | 107 | public function execute() |
| 108 | 108 | { |
| 109 | - if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE))) |
|
| 110 | - throw new QueryException('Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER); |
|
| 109 | + if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE))) { |
|
| 110 | + throw new QueryException('Where clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER); |
|
| 111 | + } |
|
| 111 | 112 | |
| 112 | 113 | return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
| 113 | 114 | } |
@@ -96,8 +96,9 @@ |
||
| 96 | 96 | public function execute() |
| 97 | 97 | { |
| 98 | 98 | |
| 99 | - if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE))) |
|
| 100 | - throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER); |
|
| 99 | + if ($this->queryStructure->getElement((QueryStructure::WHERE_TRIGGER)) && !count($this->queryStructure->getElement(QueryStructure::WHERE))) { |
|
| 100 | + throw new QueryException('Where or Having clause is required for this statement!', QueryException::QUERY_ERROR_DELETE_NOT_FILTER); |
|
| 101 | + } |
|
| 101 | 102 | |
| 102 | 103 | return DbService::getInstance()->query($this->getSyntax(), $this->queryStructure->getElement(QueryStructure::BIND_PARAMS)); |
| 103 | 104 | |
@@ -60,10 +60,11 @@ discard block |
||
| 60 | 60 | private function __construct() |
| 61 | 61 | { |
| 62 | 62 | $vendorCfg = __DIR__ . '/../../../../../vendor-cfg/qpdb_db_config.php'; |
| 63 | - if ( file_exists( $vendorCfg ) ) |
|
| 64 | - $this->dbConfig = require $vendorCfg; |
|
| 65 | - else |
|
| 66 | - $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php'; |
|
| 63 | + if ( file_exists( $vendorCfg ) ) { |
|
| 64 | + $this->dbConfig = require $vendorCfg; |
|
| 65 | + } else { |
|
| 66 | + $this->dbConfig = require __DIR__ . '/../../config/qpdb_db_config.php'; |
|
| 67 | + } |
|
| 67 | 68 | |
| 68 | 69 | $this->buildConfig(); |
| 69 | 70 | } |
@@ -146,8 +147,9 @@ discard block |
||
| 146 | 147 | |
| 147 | 148 | public function useTablePrefix() |
| 148 | 149 | { |
| 149 | - if ( !empty( $this->dbConfig[ 'use_table_prefix' ] ) ) |
|
| 150 | - return $this->dbConfig[ 'use_table_prefix' ]; |
|
| 150 | + if ( !empty( $this->dbConfig[ 'use_table_prefix' ] ) ) { |
|
| 151 | + return $this->dbConfig[ 'use_table_prefix' ]; |
|
| 152 | + } |
|
| 151 | 153 | |
| 152 | 154 | return false; |
| 153 | 155 | } |
@@ -182,8 +184,9 @@ discard block |
||
| 182 | 184 | private function readMasterDataConnect() |
| 183 | 185 | { |
| 184 | 186 | |
| 185 | - if ( !isset( $this->dbConfig[ 'master_data_connect' ][ 0 ] ) ) |
|
| 186 | - throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING ); |
|
| 187 | + if ( !isset( $this->dbConfig[ 'master_data_connect' ][ 0 ] ) ) { |
|
| 188 | + throw new DbException( 'Master data connect is missing', DbException::DB_ERROR_MASTER_DATA_CONNECTION_MISSING ); |
|
| 189 | + } |
|
| 187 | 190 | |
| 188 | 191 | $dataConnection = $this->dbConfig[ 'master_data_connect' ]; |
| 189 | 192 | |
@@ -66,14 +66,12 @@ discard block |
||
| 66 | 66 | $statement === self::QUERY_TYPE_EXPLAIN |
| 67 | 67 | ) { |
| 68 | 68 | return $this->sQuery->fetchAll( $fetchMode ); |
| 69 | - } |
|
| 70 | - elseif ( $statement === self::QUERY_TYPE_INSERT || |
|
| 69 | + } elseif ( $statement === self::QUERY_TYPE_INSERT || |
|
| 71 | 70 | $statement === self::QUERY_TYPE_UPDATE || |
| 72 | 71 | $statement === self::QUERY_TYPE_DELETE |
| 73 | 72 | ) { |
| 74 | 73 | return $this->sQuery->rowCount(); |
| 75 | - } |
|
| 76 | - else { |
|
| 74 | + } else { |
|
| 77 | 75 | |
| 78 | 76 | return NULL; |
| 79 | 77 | } |
@@ -91,8 +89,9 @@ discard block |
||
| 91 | 89 | $query = trim( str_replace( "\r", " ", $query ) ); |
| 92 | 90 | $statement = self::getQueryStatement( $query ); |
| 93 | 91 | |
| 94 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 95 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 92 | + if ( $statement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 93 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 94 | + } |
|
| 96 | 95 | |
| 97 | 96 | $Columns = $this->sQuery->fetchAll( \PDO::FETCH_NUM ); |
| 98 | 97 | |
@@ -112,8 +111,9 @@ discard block |
||
| 112 | 111 | $query = trim( str_replace( "\r", " ", $query ) ); |
| 113 | 112 | $statement = self::getQueryStatement( $query ); |
| 114 | 113 | |
| 115 | - if ( $statement === self::QUERY_TYPE_EXPLAIN ) |
|
| 116 | - return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 114 | + if ( $statement === self::QUERY_TYPE_EXPLAIN ) { |
|
| 115 | + return $this->sQuery->fetchAll( \PDO::FETCH_ASSOC ); |
|
| 116 | + } |
|
| 117 | 117 | |
| 118 | 118 | $result = $this->sQuery->fetch( $fetchmode ); |
| 119 | 119 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued, |
@@ -150,24 +150,22 @@ discard block |
||
| 150 | 150 | /** |
| 151 | 151 | * Add parameters to the parameter array |
| 152 | 152 | */ |
| 153 | - if ( self::isArrayAssoc( $parameters ) ) |
|
| 154 | - $this->bindMore( $parameters ); |
|
| 155 | - else |
|
| 156 | - foreach ( $parameters as $key => $val ) |
|
| 153 | + if ( self::isArrayAssoc( $parameters ) ) { |
|
| 154 | + $this->bindMore( $parameters ); |
|
| 155 | + } else { |
|
| 156 | + foreach ( $parameters as $key => $val ) |
|
| 157 | 157 | $this->parameters[] = array( $key + 1, $val ); |
| 158 | + } |
|
| 158 | 159 | |
| 159 | 160 | if ( count( $this->parameters ) ) { |
| 160 | 161 | foreach ( $this->parameters as $param => $value ) { |
| 161 | 162 | if ( is_int( $value[ 1 ] ) ) { |
| 162 | 163 | $type = \PDO::PARAM_INT; |
| 163 | - } |
|
| 164 | - elseif ( is_bool( $value[ 1 ] ) ) { |
|
| 164 | + } elseif ( is_bool( $value[ 1 ] ) ) { |
|
| 165 | 165 | $type = \PDO::PARAM_BOOL; |
| 166 | - } |
|
| 167 | - elseif ( is_null( $value[ 1 ] ) ) { |
|
| 166 | + } elseif ( is_null( $value[ 1 ] ) ) { |
|
| 168 | 167 | $type = \PDO::PARAM_NULL; |
| 169 | - } |
|
| 170 | - else { |
|
| 168 | + } else { |
|
| 171 | 169 | $type = \PDO::PARAM_STR; |
| 172 | 170 | } |
| 173 | 171 | $this->sQuery->bindValue( $value[ 0 ], $value[ 1 ], $type ); |
@@ -246,8 +244,7 @@ discard block |
||
| 246 | 244 | default: |
| 247 | 245 | return self::QUERY_TYPE_OTHER; |
| 248 | 246 | } |
| 249 | - } |
|
| 250 | - else { |
|
| 247 | + } else { |
|
| 251 | 248 | return self::QUERY_TYPE_OTHER; |
| 252 | 249 | } |
| 253 | 250 | } |
@@ -258,8 +255,9 @@ discard block |
||
| 258 | 255 | */ |
| 259 | 256 | public static function isArrayAssoc( array $arr ) |
| 260 | 257 | { |
| 261 | - if ( array() === $arr ) |
|
| 262 | - return false; |
|
| 258 | + if ( array() === $arr ) { |
|
| 259 | + return false; |
|
| 260 | + } |
|
| 263 | 261 | |
| 264 | 262 | return array_keys( $arr ) !== range( 0, count( $arr ) - 1 ); |
| 265 | 263 | } |
@@ -87,8 +87,9 @@ discard block |
||
| 87 | 87 | $newArray = array(); |
| 88 | 88 | foreach ( $brutArray as $value ) { |
| 89 | 89 | $value = trim( $value ); |
| 90 | - if ( '' !== $value ) |
|
| 91 | - $newArray[] = $value; |
|
| 90 | + if ( '' !== $value ) { |
|
| 91 | + $newArray[] = $value; |
|
| 92 | + } |
|
| 92 | 93 | } |
| 93 | 94 | |
| 94 | 95 | return $newArray; |
@@ -138,8 +139,9 @@ discard block |
||
| 138 | 139 | $characters = 'abcdefghijklmnopqrstuvwxyz'; |
| 139 | 140 | $charactersLength = strlen( $characters ); |
| 140 | 141 | $randomString = ''; |
| 141 | - for ( $i = 0; $i < $length; $i++ ) |
|
| 142 | - $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
| 142 | + for ( $i = 0; $i < $length; $i++ ) { |
|
| 143 | + $randomString .= $characters[ rand( 0, $charactersLength - 1 ) ]; |
|
| 144 | + } |
|
| 143 | 145 | |
| 144 | 146 | return str_shuffle( $randomString ); |
| 145 | 147 | } |
@@ -147,8 +149,9 @@ discard block |
||
| 147 | 149 | public static function limitString( $rowCount, $offset = null ) |
| 148 | 150 | { |
| 149 | 151 | $rowCount = intval( $rowCount ); |
| 150 | - if ( is_null( $offset ) ) |
|
| 151 | - return $rowCount; |
|
| 152 | + if ( is_null( $offset ) ) { |
|
| 153 | + return $rowCount; |
|
| 154 | + } |
|
| 152 | 155 | $offset = intval( $offset ); |
| 153 | 156 | |
| 154 | 157 | return "$offset, $rowCount"; |
@@ -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 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 | $this->queryStructure->setElement( QueryStructure::ORDER_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 ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 51 | + if ( !$this->validateColumn( $column, $allowedColumns ) ) { |
|
| 52 | + throw new QueryException( 'Invalid column name in ORDER BY clause', QueryException::QUERY_ERROR_INVALID_COLUMN_NAME ); |
|
| 53 | + } |
|
| 52 | 54 | |
| 53 | 55 | $this->queryStructure->setElement( QueryStructure::ORDER_BY, $column . ' DESC' ); |
| 54 | 56 | |
@@ -73,8 +75,9 @@ discard block |
||
| 73 | 75 | */ |
| 74 | 76 | private function getOrderBySyntax() |
| 75 | 77 | { |
| 76 | - if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) |
|
| 77 | - return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
| 78 | + if ( count( $this->queryStructure->getElement( QueryStructure::ORDER_BY ) ) ) { |
|
| 79 | + return 'ORDER BY ' . QueryHelper::implode( $this->queryStructure->getElement( QueryStructure::ORDER_BY ), ', ' ); |
|
| 80 | + } |
|
| 78 | 81 | |
| 79 | 82 | return ''; |
| 80 | 83 | } |