@@ -73,7 +73,8 @@ |
||
| 73 | 73 | { |
| 74 | 74 | $this->currentDriverIdentifier = $connection_identifier; |
| 75 | 75 | |
| 76 | - if (!isset(self::$drivers[$connection_identifier])) |
|
| 77 | - self::$drivers[$connection_identifier] = new DriverAdapter($connection_identifier, $auto_connect); |
|
| 76 | + if (!isset(self::$drivers[$connection_identifier])) { |
|
| 77 | + self::$drivers[$connection_identifier] = new DriverAdapter($connection_identifier, $auto_connect); |
|
| 78 | + } |
|
| 78 | 79 | } |
| 79 | 80 | } |
| 80 | 81 | \ No newline at end of file |
@@ -73,11 +73,11 @@ discard block |
||
| 73 | 73 | { |
| 74 | 74 | $k++; |
| 75 | 75 | |
| 76 | - if (is_null($value)) |
|
| 77 | - $parsed_where[] = "$key IS NULL"; |
|
| 78 | - elseif ($value instanceof SQLFunction) |
|
| 79 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 80 | - elseif (is_array($value)) |
|
| 76 | + if (is_null($value)) { |
|
| 77 | + $parsed_where[] = "$key IS NULL"; |
|
| 78 | + } elseif ($value instanceof SQLFunction) { |
|
| 79 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 80 | + } elseif (is_array($value)) |
|
| 81 | 81 | { |
| 82 | 82 | $parsed_in = []; |
| 83 | 83 | |
@@ -100,8 +100,7 @@ discard block |
||
| 100 | 100 | } |
| 101 | 101 | |
| 102 | 102 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 103 | - } |
|
| 104 | - else |
|
| 103 | + } else |
|
| 105 | 104 | { |
| 106 | 105 | switch ($driver) |
| 107 | 106 | { |
@@ -119,9 +118,9 @@ discard block |
||
| 119 | 118 | } |
| 120 | 119 | |
| 121 | 120 | $where = "WHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
| 121 | + } else { |
|
| 122 | + $where = ""; |
|
| 122 | 123 | } |
| 123 | - else |
|
| 124 | - $where = ""; |
|
| 125 | 124 | |
| 126 | 125 | $table = $this->entity->getTableName(); |
| 127 | 126 | |
@@ -144,8 +143,9 @@ discard block |
||
| 144 | 143 | */ |
| 145 | 144 | public function insert(Array $data) |
| 146 | 145 | { |
| 147 | - if (!count($data)) |
|
| 148 | - throw new \LogicException("Missing values for INSERT statement!"); |
|
| 146 | + if (!count($data)) { |
|
| 147 | + throw new \LogicException("Missing values for INSERT statement!"); |
|
| 148 | + } |
|
| 149 | 149 | |
| 150 | 150 | $bind_values = []; |
| 151 | 151 | |
@@ -168,11 +168,11 @@ discard block |
||
| 168 | 168 | continue; |
| 169 | 169 | } |
| 170 | 170 | |
| 171 | - if (is_null($value)) |
|
| 172 | - $value = "NULL"; |
|
| 173 | - elseif ($value instanceof SQLFunction) |
|
| 174 | - $value = $value->getStatement(); |
|
| 175 | - else { |
|
| 171 | + if (is_null($value)) { |
|
| 172 | + $value = "NULL"; |
|
| 173 | + } elseif ($value instanceof SQLFunction) { |
|
| 174 | + $value = $value->getStatement(); |
|
| 175 | + } else { |
|
| 176 | 176 | |
| 177 | 177 | switch ($driver) |
| 178 | 178 | { |
@@ -222,11 +222,13 @@ discard block |
||
| 222 | 222 | { |
| 223 | 223 | $parsed_set = []; |
| 224 | 224 | |
| 225 | - if (!count($set)) |
|
| 226 | - throw new \LogicException("You cannot update rows without SET clause"); |
|
| 225 | + if (!count($set)) { |
|
| 226 | + throw new \LogicException("You cannot update rows without SET clause"); |
|
| 227 | + } |
|
| 227 | 228 | |
| 228 | - if (!count($where)) |
|
| 229 | - throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
| 229 | + if (!count($where)) { |
|
| 230 | + throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
| 231 | + } |
|
| 230 | 232 | |
| 231 | 233 | $bind_values = []; |
| 232 | 234 | |
@@ -238,11 +240,11 @@ discard block |
||
| 238 | 240 | { |
| 239 | 241 | $k++; |
| 240 | 242 | |
| 241 | - if (is_null($value)) |
|
| 242 | - $parsed_set[] = "$key = NULL"; |
|
| 243 | - elseif ($value instanceof SQLFunction) |
|
| 244 | - $parsed_set[] = "$key = " . $value->getStatement(); |
|
| 245 | - elseif (is_array($value)) |
|
| 243 | + if (is_null($value)) { |
|
| 244 | + $parsed_set[] = "$key = NULL"; |
|
| 245 | + } elseif ($value instanceof SQLFunction) { |
|
| 246 | + $parsed_set[] = "$key = " . $value->getStatement(); |
|
| 247 | + } elseif (is_array($value)) |
|
| 246 | 248 | { |
| 247 | 249 | $parsed_in = []; |
| 248 | 250 | |
@@ -253,8 +255,9 @@ discard block |
||
| 253 | 255 | case 'Oci8': |
| 254 | 256 | |
| 255 | 257 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
| 256 | - if (is_string($in_value)) |
|
| 257 | - $parsed_in[] = ":$k"; |
|
| 258 | + if (is_string($in_value)) { |
|
| 259 | + $parsed_in[] = ":$k"; |
|
| 260 | + } |
|
| 258 | 261 | |
| 259 | 262 | $bind_values[":$k"] = $in_value; |
| 260 | 263 | break; |
@@ -269,8 +272,7 @@ discard block |
||
| 269 | 272 | } |
| 270 | 273 | |
| 271 | 274 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 272 | - } |
|
| 273 | - else |
|
| 275 | + } else |
|
| 274 | 276 | { |
| 275 | 277 | switch ($driver) |
| 276 | 278 | { |
@@ -296,11 +298,11 @@ discard block |
||
| 296 | 298 | { |
| 297 | 299 | $k++; |
| 298 | 300 | |
| 299 | - if (is_null($value)) |
|
| 300 | - $parsed_where[] = "$key IS NULL"; |
|
| 301 | - elseif ($value instanceof SQLFunction) |
|
| 302 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 303 | - elseif (is_array($value)) |
|
| 301 | + if (is_null($value)) { |
|
| 302 | + $parsed_where[] = "$key IS NULL"; |
|
| 303 | + } elseif ($value instanceof SQLFunction) { |
|
| 304 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 305 | + } elseif (is_array($value)) |
|
| 304 | 306 | { |
| 305 | 307 | $parsed_in = []; |
| 306 | 308 | |
@@ -323,8 +325,7 @@ discard block |
||
| 323 | 325 | } |
| 324 | 326 | |
| 325 | 327 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 326 | - } |
|
| 327 | - else |
|
| 328 | + } else |
|
| 328 | 329 | { |
| 329 | 330 | switch ($driver) |
| 330 | 331 | { |
@@ -376,11 +377,11 @@ discard block |
||
| 376 | 377 | { |
| 377 | 378 | $k++; |
| 378 | 379 | |
| 379 | - if (is_null($value)) |
|
| 380 | - $parsed_where[] = "$key IS NULL"; |
|
| 381 | - elseif ($value instanceof SQLFunction) |
|
| 382 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 383 | - elseif (is_array($value)) |
|
| 380 | + if (is_null($value)) { |
|
| 381 | + $parsed_where[] = "$key IS NULL"; |
|
| 382 | + } elseif ($value instanceof SQLFunction) { |
|
| 383 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 384 | + } elseif (is_array($value)) |
|
| 384 | 385 | { |
| 385 | 386 | $parsed_in = []; |
| 386 | 387 | |
@@ -403,8 +404,7 @@ discard block |
||
| 403 | 404 | } |
| 404 | 405 | |
| 405 | 406 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 406 | - } |
|
| 407 | - else |
|
| 407 | + } else |
|
| 408 | 408 | { |
| 409 | 409 | switch ($driver) |
| 410 | 410 | { |
@@ -422,9 +422,9 @@ discard block |
||
| 422 | 422 | } |
| 423 | 423 | |
| 424 | 424 | $where = "\r\nWHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
| 425 | + } else { |
|
| 426 | + throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
| 425 | 427 | } |
| 426 | - else |
|
| 427 | - throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
| 428 | 428 | |
| 429 | 429 | $table = $this->entity->getTableName(); |
| 430 | 430 | |
@@ -58,8 +58,9 @@ discard block |
||
| 58 | 58 | { |
| 59 | 59 | $result = $this->tableGateway->select($where); |
| 60 | 60 | |
| 61 | - if (!count($result)) |
|
| 62 | - return $result; |
|
| 61 | + if (!count($result)) { |
|
| 62 | + return $result; |
|
| 63 | + } |
|
| 63 | 64 | |
| 64 | 65 | $array_result = []; |
| 65 | 66 | |
@@ -69,8 +70,9 @@ discard block |
||
| 69 | 70 | |
| 70 | 71 | foreach ($row as $key => $value) |
| 71 | 72 | { |
| 72 | - if (is_string($key)) |
|
| 73 | - $filtered_array[$key] = $value; |
|
| 73 | + if (is_string($key)) { |
|
| 74 | + $filtered_array[$key] = $value; |
|
| 75 | + } |
|
| 74 | 76 | } |
| 75 | 77 | |
| 76 | 78 | $user_entity = get_class($this->tableGateway->getEntity()); |
@@ -94,10 +96,11 @@ discard block |
||
| 94 | 96 | */ |
| 95 | 97 | public function insert($entity) |
| 96 | 98 | { |
| 97 | - if ($entity instanceof Entity) |
|
| 98 | - $entity = get_object_vars($entity); |
|
| 99 | - else if (!is_array($entity)) |
|
| 100 | - throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 99 | + if ($entity instanceof Entity) { |
|
| 100 | + $entity = get_object_vars($entity); |
|
| 101 | + } else if (!is_array($entity)) { |
|
| 102 | + throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 103 | + } |
|
| 101 | 104 | |
| 102 | 105 | $this->parseEntity($entity); |
| 103 | 106 | |
@@ -126,14 +129,15 @@ discard block |
||
| 126 | 129 | |
| 127 | 130 | foreach ($entity as $key => $value) |
| 128 | 131 | { |
| 129 | - if (in_array($key, $changedFields)) |
|
| 130 | - $fieldsToModify[$key] = $value; |
|
| 132 | + if (in_array($key, $changedFields)) { |
|
| 133 | + $fieldsToModify[$key] = $value; |
|
| 134 | + } |
|
| 131 | 135 | } |
| 132 | 136 | |
| 133 | 137 | $entity = $fieldsToModify; |
| 138 | + } else if (!is_array($entity)) { |
|
| 139 | + throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 134 | 140 | } |
| 135 | - else if (!is_array($entity)) |
|
| 136 | - throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 137 | 141 | |
| 138 | 142 | $this->parseEntity($entity); |
| 139 | 143 | |
@@ -152,10 +156,11 @@ discard block |
||
| 152 | 156 | */ |
| 153 | 157 | public function delete($entity) |
| 154 | 158 | { |
| 155 | - if ($entity instanceof Entity) |
|
| 156 | - $entity = get_object_vars($entity); |
|
| 157 | - else if (!is_array($entity)) |
|
| 158 | - throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 159 | + if ($entity instanceof Entity) { |
|
| 160 | + $entity = get_object_vars($entity); |
|
| 161 | + } else if (!is_array($entity)) { |
|
| 162 | + throw new \InvalidArgumentException("Invalid type given. Drone\Db\Entity or Array expected"); |
|
| 163 | + } |
|
| 159 | 164 | |
| 160 | 165 | return $this->tableGateway->delete($entity); |
| 161 | 166 | } |