@@ -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 | } |
@@ -28,8 +28,9 @@ |
||
| 28 | 28 | |
| 29 | 29 | protected function getExplainSyntax() |
| 30 | 30 | { |
| 31 | - if ($this->queryStructure->getElement(QueryStructure::EXPLAIN)) |
|
| 32 | - return 'EXPLAIN'; |
|
| 31 | + if ($this->queryStructure->getElement(QueryStructure::EXPLAIN)) { |
|
| 32 | + return 'EXPLAIN'; |
|
| 33 | + } |
|
| 33 | 34 | |
| 34 | 35 | return ''; |
| 35 | 36 | } |
@@ -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"; |
@@ -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 | |
@@ -142,15 +143,19 @@ discard block |
||
| 142 | 143 | */ |
| 143 | 144 | public function setElement($name, $value) |
| 144 | 145 | { |
| 145 | - if (!array_key_exists($name, $this->syntaxEL)) |
|
| 146 | - throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
| 146 | + if (!array_key_exists($name, $this->syntaxEL)) { |
|
| 147 | + throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
| 148 | + } |
|
| 147 | 149 | |
| 148 | - if ($name == self::TABLE && is_a($value, QueryStatement::class)) |
|
| 149 | - return true; |
|
| 150 | + if ($name == self::TABLE && is_a($value, QueryStatement::class)) { |
|
| 151 | + return true; |
|
| 152 | + } |
|
| 150 | 153 | |
| 151 | - if ($this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY) |
|
| 152 | - $this->syntaxEL[ $name ][] = $value; else |
|
| 153 | - $this->syntaxEL[ $name ] = $value; |
|
| 154 | + if ($this->typeEL[ $name ] === self::ELEMENT_TYPE_ARRAY) { |
|
| 155 | + $this->syntaxEL[ $name ][] = $value; |
|
| 156 | + } else { |
|
| 157 | + $this->syntaxEL[ $name ] = $value; |
|
| 158 | + } |
|
| 154 | 159 | |
| 155 | 160 | return true; |
| 156 | 161 | } |
@@ -163,8 +168,9 @@ discard block |
||
| 163 | 168 | */ |
| 164 | 169 | public function replaceElement($elementName, $elementValue) |
| 165 | 170 | { |
| 166 | - if (!array_key_exists($elementName, $this->syntaxEL)) |
|
| 167 | - throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
| 171 | + if (!array_key_exists($elementName, $this->syntaxEL)) { |
|
| 172 | + throw new QueryException('Invalid Query property', QueryException::QUERY_ERROR_ELEMENT_NOT_FOUND); |
|
| 173 | + } |
|
| 168 | 174 | |
| 169 | 175 | $this->syntaxEL[ $elementName ] = $elementValue; |
| 170 | 176 | } |
@@ -212,11 +218,13 @@ discard block |
||
| 212 | 218 | */ |
| 213 | 219 | public function bindParamsExpression($expression, array $params = [], $search = '?') |
| 214 | 220 | { |
| 215 | - if (!count($params)) |
|
| 216 | - return $expression; |
|
| 221 | + if (!count($params)) { |
|
| 222 | + return $expression; |
|
| 223 | + } |
|
| 217 | 224 | |
| 218 | - if (strpos($expression, $search) === false) |
|
| 219 | - return $expression; |
|
| 225 | + if (strpos($expression, $search) === false) { |
|
| 226 | + return $expression; |
|
| 227 | + } |
|
| 220 | 228 | |
| 221 | 229 | $params = array_slice($params, 0, substr_count($expression, $search)); |
| 222 | 230 | |
@@ -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 | |
@@ -135,10 +135,12 @@ discard block |
||
| 135 | 135 | /** |
| 136 | 136 | * Add parameters to the parameter array |
| 137 | 137 | */ |
| 138 | - if (self::isArrayAssoc($parameters)) |
|
| 139 | - $this->bindMore($parameters); else |
|
| 140 | - foreach ($parameters as $key => $val) |
|
| 138 | + if (self::isArrayAssoc($parameters)) { |
|
| 139 | + $this->bindMore($parameters); |
|
| 140 | + } else { |
|
| 141 | + foreach ($parameters as $key => $val) |
|
| 141 | 142 | $this->parameters[] = array($key + 1, $val); |
| 143 | + } |
|
| 142 | 144 | |
| 143 | 145 | if (count($this->parameters)) { |
| 144 | 146 | foreach ($this->parameters as $param => $value) { |
@@ -181,8 +183,9 @@ discard block |
||
| 181 | 183 | */ |
| 182 | 184 | public static function isArrayAssoc(array $arr) |
| 183 | 185 | { |
| 184 | - if (array() === $arr) |
|
| 185 | - return false; |
|
| 186 | + if (array() === $arr) { |
|
| 187 | + return false; |
|
| 188 | + } |
|
| 186 | 189 | |
| 187 | 190 | return array_keys($arr) !== range(0, count($arr) - 1); |
| 188 | 191 | } |
@@ -214,8 +217,9 @@ discard block |
||
| 214 | 217 | $query = trim(str_replace("\r", " ", $query)); |
| 215 | 218 | $statement = self::getQueryStatement($query); |
| 216 | 219 | |
| 217 | - if ($statement === self::QUERY_TYPE_EXPLAIN) |
|
| 218 | - return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 220 | + if ($statement === self::QUERY_TYPE_EXPLAIN) { |
|
| 221 | + return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 222 | + } |
|
| 219 | 223 | |
| 220 | 224 | $Columns = $this->sQuery->fetchAll(\PDO::FETCH_NUM); |
| 221 | 225 | |
@@ -235,8 +239,9 @@ discard block |
||
| 235 | 239 | $query = trim(str_replace("\r", " ", $query)); |
| 236 | 240 | $statement = self::getQueryStatement($query); |
| 237 | 241 | |
| 238 | - if ($statement === self::QUERY_TYPE_EXPLAIN) |
|
| 239 | - return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 242 | + if ($statement === self::QUERY_TYPE_EXPLAIN) { |
|
| 243 | + return $this->sQuery->fetchAll(\PDO::FETCH_ASSOC); |
|
| 244 | + } |
|
| 240 | 245 | |
| 241 | 246 | $result = $this->sQuery->fetch($fetchmode); |
| 242 | 247 | $this->sQuery->closeCursor(); // Frees up the connection to the server so that other SQL statements may be issued, |
@@ -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 | } |