@@ -94,7 +94,7 @@ discard block |
||
| 94 | 94 | break; |
| 95 | 95 | |
| 96 | 96 | case self::LAST_YEAR: |
| 97 | - $year = ((int) date('Y'))- 1; |
|
| 97 | + $year = ((int) date('Y')) - 1; |
|
| 98 | 98 | break; |
| 99 | 99 | |
| 100 | 100 | default: |
@@ -142,7 +142,7 @@ discard block |
||
| 142 | 142 | $d->setDate($year, (int) $d->format('m'), (int) $d->format('d')); |
| 143 | 143 | } |
| 144 | 144 | |
| 145 | - $d->add(new \DateInterval('P'.($day - 1).'D')); |
|
| 145 | + $d->add(new \DateInterval('P' . ($day - 1) . 'D')); |
|
| 146 | 146 | } |
| 147 | 147 | |
| 148 | 148 | return $d; |
@@ -63,8 +63,9 @@ discard block |
||
| 63 | 63 | */ |
| 64 | 64 | public static function getMonth($month_number) |
| 65 | 65 | { |
| 66 | - if (!array_key_exists($month_number, self::MONTHS)) |
|
| 67 | - throw new Exception\MonthOutOfRange("Invalid Month"); |
|
| 66 | + if (!array_key_exists($month_number, self::MONTHS)) { |
|
| 67 | + throw new Exception\MonthOutOfRange("Invalid Month"); |
|
| 68 | + } |
|
| 68 | 69 | |
| 69 | 70 | return self::MONTHS[$month_number]; |
| 70 | 71 | } |
@@ -78,14 +79,17 @@ discard block |
||
| 78 | 79 | */ |
| 79 | 80 | public static function create(array $date = []) |
| 80 | 81 | { |
| 81 | - if (!array_key_exists('day', $date)) |
|
| 82 | - $date["day"] = self::TODAY; |
|
| 82 | + if (!array_key_exists('day', $date)) { |
|
| 83 | + $date["day"] = self::TODAY; |
|
| 84 | + } |
|
| 83 | 85 | |
| 84 | - if (!array_key_exists('month', $date)) |
|
| 85 | - $date["month"] = self::THIS_MONTH; |
|
| 86 | + if (!array_key_exists('month', $date)) { |
|
| 87 | + $date["month"] = self::THIS_MONTH; |
|
| 88 | + } |
|
| 86 | 89 | |
| 87 | - if (!array_key_exists('year', $date)) |
|
| 88 | - $date["year"] = self::THIS_YEAR; |
|
| 90 | + if (!array_key_exists('year', $date)) { |
|
| 91 | + $date["year"] = self::THIS_YEAR; |
|
| 92 | + } |
|
| 89 | 93 | |
| 90 | 94 | switch ($date['year']) |
| 91 | 95 | { |
@@ -130,13 +134,13 @@ discard block |
||
| 130 | 134 | break; |
| 131 | 135 | } |
| 132 | 136 | |
| 133 | - if (is_string($day)) |
|
| 134 | - $d = new \DateTime("$day $month $year"); |
|
| 135 | - else |
|
| 137 | + if (is_string($day)) { |
|
| 138 | + $d = new \DateTime("$day $month $year"); |
|
| 139 | + } else |
|
| 136 | 140 | { |
| 137 | - if (in_array($month, self::MONTHS)) |
|
| 138 | - $d = new \DateTime("first day of $month $year"); |
|
| 139 | - else |
|
| 141 | + if (in_array($month, self::MONTHS)) { |
|
| 142 | + $d = new \DateTime("first day of $month $year"); |
|
| 143 | + } else |
|
| 140 | 144 | { |
| 141 | 145 | $d = new \DateTime("first day of $month"); |
| 142 | 146 | $d->setDate($year, (int) $d->format('m'), (int) $d->format('d')); |
@@ -126,7 +126,7 @@ |
||
| 126 | 126 | public function getContentsFromUrl($filename) |
| 127 | 127 | { |
| 128 | 128 | $headers = get_headers($url); |
| 129 | - $exists = stripos($headers[0],"200 OK") ? true : false; |
|
| 129 | + $exists = stripos($headers[0], "200 OK") ? true : false; |
|
| 130 | 130 | |
| 131 | 131 | if ($exists) |
| 132 | 132 | return file_get_contents($filename); |
@@ -90,13 +90,11 @@ discard block |
||
| 90 | 90 | try |
| 91 | 91 | { |
| 92 | 92 | $ctrl->addNonExistingError(); |
| 93 | - } |
|
| 94 | - catch (\Exception $e) |
|
| 93 | + } catch (\Exception $e) |
|
| 95 | 94 | { |
| 96 | 95 | $errorObject = ($e instanceof \LogicException); |
| 97 | 96 | $message = $e->getMessage(); |
| 98 | - } |
|
| 99 | - finally |
|
| 97 | + } finally |
|
| 100 | 98 | { |
| 101 | 99 | $this->assertTrue($errorObject, $message); |
| 102 | 100 | } |
@@ -109,18 +107,20 @@ discard block |
||
| 109 | 107 | |
| 110 | 108 | public function getContentsFromFile($filename) |
| 111 | 109 | { |
| 112 | - if (file_exists($filename)) |
|
| 113 | - return file_get_contents($filename); |
|
| 114 | - else |
|
| 115 | - $this->error(Errno::FILE_NOT_FOUND, $filename); |
|
| 110 | + if (file_exists($filename)) { |
|
| 111 | + return file_get_contents($filename); |
|
| 112 | + } else { |
|
| 113 | + $this->error(Errno::FILE_NOT_FOUND, $filename); |
|
| 114 | + } |
|
| 116 | 115 | } |
| 117 | 116 | |
| 118 | 117 | public function getContentsFromFileWithoutFilenameOnError($filename) |
| 119 | 118 | { |
| 120 | - if (file_exists($filename)) |
|
| 121 | - return file_get_contents($filename); |
|
| 122 | - else |
|
| 123 | - $this->error(Errno::FILE_NOT_FOUND); |
|
| 119 | + if (file_exists($filename)) { |
|
| 120 | + return file_get_contents($filename); |
|
| 121 | + } else { |
|
| 122 | + $this->error(Errno::FILE_NOT_FOUND); |
|
| 123 | + } |
|
| 124 | 124 | } |
| 125 | 125 | |
| 126 | 126 | public function getContentsFromUrl($filename) |
@@ -128,10 +128,11 @@ discard block |
||
| 128 | 128 | $headers = get_headers($url); |
| 129 | 129 | $exists = stripos($headers[0],"200 OK") ? true : false; |
| 130 | 130 | |
| 131 | - if ($exists) |
|
| 132 | - return file_get_contents($filename); |
|
| 133 | - else |
|
| 134 | - $this->error("URL not found"); |
|
| 131 | + if ($exists) { |
|
| 132 | + return file_get_contents($filename); |
|
| 133 | + } else { |
|
| 134 | + $this->error("URL not found"); |
|
| 135 | + } |
|
| 135 | 136 | } |
| 136 | 137 | |
| 137 | 138 | public function addNonExistingError() |
@@ -39,13 +39,11 @@ |
||
| 39 | 39 | try |
| 40 | 40 | { |
| 41 | 41 | $this->assertEquals('June', Dt::getMonth(13)); |
| 42 | - } |
|
| 43 | - catch (\Exception $e) |
|
| 42 | + } catch (\Exception $e) |
|
| 44 | 43 | { |
| 45 | 44 | $errorObject = ($e instanceof MonthOutOfRange); |
| 46 | 45 | $message = $e->getMessage(); |
| 47 | - } |
|
| 48 | - finally |
|
| 46 | + } finally |
|
| 49 | 47 | { |
| 50 | 48 | $this->assertTrue($errorObject, $message); |
| 51 | 49 | } |
@@ -87,24 +87,25 @@ discard block |
||
| 87 | 87 | { |
| 88 | 88 | $this->currentConnection = $connection; |
| 89 | 89 | $this->getDriver($connection); |
| 90 | - } |
|
| 91 | - else if (is_array($connection)) |
|
| 90 | + } else if (is_array($connection)) |
|
| 92 | 91 | { |
| 93 | 92 | $identifier = key($connection); |
| 94 | 93 | $connection_options = $connection[$identifier]; |
| 95 | 94 | |
| 96 | 95 | $this->currentConnection = $identifier; |
| 97 | 96 | |
| 98 | - if (!array_key_exists('driver', $connection_options)) |
|
| 99 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
| 100 | - |
|
| 101 | - if (!isset(self::$drivers[$identifier])) |
|
| 102 | - self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
| 103 | - else |
|
| 104 | - throw new \RuntimeException("The database connection already exists"); |
|
| 97 | + if (!array_key_exists('driver', $connection_options)) { |
|
| 98 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
| 99 | + } |
|
| 100 | + |
|
| 101 | + if (!isset(self::$drivers[$identifier])) { |
|
| 102 | + self::$drivers[$identifier] = DriverFactory::create($connection_options); |
|
| 103 | + } else { |
|
| 104 | + throw new \RuntimeException("The database connection already exists"); |
|
| 105 | + } |
|
| 106 | + } else { |
|
| 107 | + throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
| 105 | 108 | } |
| 106 | - else |
|
| 107 | - throw new \InvalidArgumentException("Invalid type given. Array or string expected"); |
|
| 108 | 109 | } |
| 109 | 110 | |
| 110 | 111 | /** |
@@ -118,8 +119,9 @@ discard block |
||
| 118 | 119 | */ |
| 119 | 120 | public static function getDriver($identifier) |
| 120 | 121 | { |
| 121 | - if (!array_key_exists($identifier, self::$drivers)) |
|
| 122 | - throw new \RuntimeException("The database connection does not exists"); |
|
| 122 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
| 123 | + throw new \RuntimeException("The database connection does not exists"); |
|
| 124 | + } |
|
| 123 | 125 | |
| 124 | 126 | return self::$drivers[$identifier]; |
| 125 | 127 | } |
@@ -135,8 +137,9 @@ discard block |
||
| 135 | 137 | */ |
| 136 | 138 | public static function hasDriver($identifier) |
| 137 | 139 | { |
| 138 | - if (!array_key_exists($identifier, self::$drivers)) |
|
| 139 | - return false; |
|
| 140 | + if (!array_key_exists($identifier, self::$drivers)) { |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 140 | 143 | |
| 141 | 144 | return true; |
| 142 | 145 | } |
@@ -34,14 +34,16 @@ |
||
| 34 | 34 | "Sqlsrv" => "Drone\Db\Driver\SQLServer", |
| 35 | 35 | ]; |
| 36 | 36 | |
| 37 | - if (!array_key_exists('driver', $connection_options)) |
|
| 38 | - throw new \RuntimeException("The database driver key has not been declared"); |
|
| 37 | + if (!array_key_exists('driver', $connection_options)) { |
|
| 38 | + throw new \RuntimeException("The database driver key has not been declared"); |
|
| 39 | + } |
|
| 39 | 40 | |
| 40 | 41 | $drv = $connection_options["driver"]; |
| 41 | 42 | |
| 42 | - if (array_key_exists($drv, $drivers)) |
|
| 43 | - return new $drivers[$drv]($connection_options); |
|
| 44 | - else |
|
| 45 | - throw new \RuntimeException("The database driver does not exists"); |
|
| 43 | + if (array_key_exists($drv, $drivers)) { |
|
| 44 | + return new $drivers[$drv]($connection_options); |
|
| 45 | + } else { |
|
| 46 | + throw new \RuntimeException("The database driver does not exists"); |
|
| 47 | + } |
|
| 46 | 48 | } |
| 47 | 49 | } |
| 48 | 50 | \ No newline at end of file |
@@ -252,7 +252,7 @@ |
||
| 252 | 252 | { |
| 253 | 253 | parent::__construct($data); |
| 254 | 254 | $this->setTableName("USER"); |
| 255 | - } |
|
| 255 | + } |
|
| 256 | 256 | } |
| 257 | 257 | |
| 258 | 258 | class UserGateway extends TableGateway |
@@ -440,7 +440,7 @@ |
||
| 440 | 440 | { |
| 441 | 441 | parent::__construct($data); |
| 442 | 442 | $this->setTableName("MYTABLE"); |
| 443 | - } |
|
| 443 | + } |
|
| 444 | 444 | } |
| 445 | 445 | |
| 446 | 446 | class MyEntityGateway extends TableGateway |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | public function testCannotEstablishConnectionWhenExists() |
| 67 | 67 | { |
| 68 | 68 | $options = $this->options; |
| 69 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 69 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 70 | 70 | |
| 71 | 71 | $entity = new MyEntity(); |
| 72 | 72 | new TableGateway($entity, ["default" => $options]); |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | public function testCannotEstablishConnection() |
| 81 | 81 | { |
| 82 | 82 | $options = $this->options; |
| 83 | - $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 83 | + $options["dbhost"] = 'myserver'; // this server does not exists |
|
| 84 | 84 | |
| 85 | 85 | $entity = new MyEntity(); |
| 86 | 86 | $gateway = new TableGateway($entity, ["other" => $options]); |
@@ -88,8 +88,7 @@ |
||
| 88 | 88 | try |
| 89 | 89 | { |
| 90 | 90 | $gateway->getDb()->connect(); |
| 91 | - } |
|
| 92 | - catch (\Exception $e) |
|
| 91 | + } catch (\Exception $e) |
|
| 93 | 92 | { |
| 94 | 93 | $this->assertNotTrue($gateway->getDb()->isConnected()); |
| 95 | 94 | throw $e; |
@@ -78,11 +78,11 @@ discard block |
||
| 78 | 78 | { |
| 79 | 79 | $k++; |
| 80 | 80 | |
| 81 | - if (is_null($value)) |
|
| 82 | - $parsed_where[] = "$key IS NULL"; |
|
| 83 | - elseif ($value instanceof SQLFunction) |
|
| 84 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 85 | - elseif (is_array($value)) |
|
| 81 | + if (is_null($value)) { |
|
| 82 | + $parsed_where[] = "$key IS NULL"; |
|
| 83 | + } elseif ($value instanceof SQLFunction) { |
|
| 84 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 85 | + } elseif (is_array($value)) |
|
| 86 | 86 | { |
| 87 | 87 | $parsed_in = []; |
| 88 | 88 | |
@@ -105,8 +105,7 @@ discard block |
||
| 105 | 105 | } |
| 106 | 106 | |
| 107 | 107 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 108 | - } |
|
| 109 | - else |
|
| 108 | + } else |
|
| 110 | 109 | { |
| 111 | 110 | switch ($driver) |
| 112 | 111 | { |
@@ -124,9 +123,9 @@ discard block |
||
| 124 | 123 | } |
| 125 | 124 | |
| 126 | 125 | $where = "WHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
| 126 | + } else { |
|
| 127 | + $where = ""; |
|
| 127 | 128 | } |
| 128 | - else |
|
| 129 | - $where = ""; |
|
| 130 | 129 | |
| 131 | 130 | $table = $this->entity->getTableName(); |
| 132 | 131 | |
@@ -135,10 +134,11 @@ discard block |
||
| 135 | 134 | $this->lastQuery = $sql; |
| 136 | 135 | $this->lastValues = $bind_values; |
| 137 | 136 | |
| 138 | - if (count($bind_values)) |
|
| 139 | - $this->getDb()->execute($sql, $bind_values); |
|
| 140 | - else |
|
| 141 | - $this->getDb()->execute($sql); |
|
| 137 | + if (count($bind_values)) { |
|
| 138 | + $this->getDb()->execute($sql, $bind_values); |
|
| 139 | + } else { |
|
| 140 | + $this->getDb()->execute($sql); |
|
| 141 | + } |
|
| 142 | 142 | |
| 143 | 143 | return $this->getDb()->getArrayResult(); |
| 144 | 144 | } |
@@ -155,8 +155,9 @@ discard block |
||
| 155 | 155 | */ |
| 156 | 156 | public function insert(Array $data) |
| 157 | 157 | { |
| 158 | - if (!count($data)) |
|
| 159 | - throw new \LogicException("Missing values for INSERT statement!"); |
|
| 158 | + if (!count($data)) { |
|
| 159 | + throw new \LogicException("Missing values for INSERT statement!"); |
|
| 160 | + } |
|
| 160 | 161 | |
| 161 | 162 | $bind_values = []; |
| 162 | 163 | |
@@ -179,11 +180,11 @@ discard block |
||
| 179 | 180 | continue; |
| 180 | 181 | } |
| 181 | 182 | |
| 182 | - if (is_null($value)) |
|
| 183 | - $value = "NULL"; |
|
| 184 | - elseif ($value instanceof SQLFunction) |
|
| 185 | - $value = $value->getStatement(); |
|
| 186 | - else { |
|
| 183 | + if (is_null($value)) { |
|
| 184 | + $value = "NULL"; |
|
| 185 | + } elseif ($value instanceof SQLFunction) { |
|
| 186 | + $value = $value->getStatement(); |
|
| 187 | + } else { |
|
| 187 | 188 | |
| 188 | 189 | switch ($driver) |
| 189 | 190 | { |
@@ -236,11 +237,13 @@ discard block |
||
| 236 | 237 | { |
| 237 | 238 | $parsed_set = []; |
| 238 | 239 | |
| 239 | - if (!count($set)) |
|
| 240 | - throw new \LogicException("You cannot update rows without SET clause"); |
|
| 240 | + if (!count($set)) { |
|
| 241 | + throw new \LogicException("You cannot update rows without SET clause"); |
|
| 242 | + } |
|
| 241 | 243 | |
| 242 | - if (!count($where)) |
|
| 243 | - throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
| 244 | + if (!count($where)) { |
|
| 245 | + throw new SecurityException("You cannot update rows without WHERE clause!"); |
|
| 246 | + } |
|
| 244 | 247 | |
| 245 | 248 | $bind_values = []; |
| 246 | 249 | |
@@ -252,11 +255,11 @@ discard block |
||
| 252 | 255 | { |
| 253 | 256 | $k++; |
| 254 | 257 | |
| 255 | - if (is_null($value)) |
|
| 256 | - $parsed_set[] = "$key = NULL"; |
|
| 257 | - elseif ($value instanceof SQLFunction) |
|
| 258 | - $parsed_set[] = "$key = " . $value->getStatement(); |
|
| 259 | - elseif (is_array($value)) |
|
| 258 | + if (is_null($value)) { |
|
| 259 | + $parsed_set[] = "$key = NULL"; |
|
| 260 | + } elseif ($value instanceof SQLFunction) { |
|
| 261 | + $parsed_set[] = "$key = " . $value->getStatement(); |
|
| 262 | + } elseif (is_array($value)) |
|
| 260 | 263 | { |
| 261 | 264 | $parsed_in = []; |
| 262 | 265 | |
@@ -267,8 +270,9 @@ discard block |
||
| 267 | 270 | case 'Oci8': |
| 268 | 271 | |
| 269 | 272 | # [POSSIBLE BUG] - To Future revision (What about non-string values ?) |
| 270 | - if (is_string($in_value)) |
|
| 271 | - $parsed_in[] = ":$k"; |
|
| 273 | + if (is_string($in_value)) { |
|
| 274 | + $parsed_in[] = ":$k"; |
|
| 275 | + } |
|
| 272 | 276 | |
| 273 | 277 | $bind_values[":$k"] = $in_value; |
| 274 | 278 | break; |
@@ -283,8 +287,7 @@ discard block |
||
| 283 | 287 | } |
| 284 | 288 | |
| 285 | 289 | $parsed_set[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 286 | - } |
|
| 287 | - else |
|
| 290 | + } else |
|
| 288 | 291 | { |
| 289 | 292 | switch ($driver) |
| 290 | 293 | { |
@@ -309,11 +312,11 @@ discard block |
||
| 309 | 312 | { |
| 310 | 313 | $k++; |
| 311 | 314 | |
| 312 | - if (is_null($value)) |
|
| 313 | - $parsed_where[] = "$key IS NULL"; |
|
| 314 | - elseif ($value instanceof SQLFunction) |
|
| 315 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 316 | - elseif (is_array($value)) |
|
| 315 | + if (is_null($value)) { |
|
| 316 | + $parsed_where[] = "$key IS NULL"; |
|
| 317 | + } elseif ($value instanceof SQLFunction) { |
|
| 318 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 319 | + } elseif (is_array($value)) |
|
| 317 | 320 | { |
| 318 | 321 | $parsed_in = []; |
| 319 | 322 | |
@@ -336,8 +339,7 @@ discard block |
||
| 336 | 339 | } |
| 337 | 340 | |
| 338 | 341 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 339 | - } |
|
| 340 | - else |
|
| 342 | + } else |
|
| 341 | 343 | { |
| 342 | 344 | switch ($driver) |
| 343 | 345 | { |
@@ -392,11 +394,11 @@ discard block |
||
| 392 | 394 | { |
| 393 | 395 | $k++; |
| 394 | 396 | |
| 395 | - if (is_null($value)) |
|
| 396 | - $parsed_where[] = "$key IS NULL"; |
|
| 397 | - elseif ($value instanceof SQLFunction) |
|
| 398 | - $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 399 | - elseif (is_array($value)) |
|
| 397 | + if (is_null($value)) { |
|
| 398 | + $parsed_where[] = "$key IS NULL"; |
|
| 399 | + } elseif ($value instanceof SQLFunction) { |
|
| 400 | + $parsed_where[] = "$key = " . $value->getStatement(); |
|
| 401 | + } elseif (is_array($value)) |
|
| 400 | 402 | { |
| 401 | 403 | $parsed_in = []; |
| 402 | 404 | |
@@ -419,8 +421,7 @@ discard block |
||
| 419 | 421 | } |
| 420 | 422 | |
| 421 | 423 | $parsed_where[] = "$key IN (" . implode(", ", $parsed_in) . ")"; |
| 422 | - } |
|
| 423 | - else |
|
| 424 | + } else |
|
| 424 | 425 | { |
| 425 | 426 | switch ($driver) |
| 426 | 427 | { |
@@ -438,9 +439,9 @@ discard block |
||
| 438 | 439 | } |
| 439 | 440 | |
| 440 | 441 | $where = "\r\nWHERE \r\n\t" . implode(" AND\r\n\t", $parsed_where); |
| 442 | + } else { |
|
| 443 | + throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
| 441 | 444 | } |
| 442 | - else |
|
| 443 | - throw new SecurityException("You cannot delete rows without WHERE clause!. Use TRUNCATE statement instead."); |
|
| 444 | 445 | |
| 445 | 446 | $table = $this->entity->getTableName(); |
| 446 | 447 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | { |
| 121 | 121 | if (is_string($param_values[$i])) |
| 122 | 122 | $bind_types .= 's'; |
| 123 | - else if(is_float($param_values[$i])) |
|
| 123 | + else if (is_float($param_values[$i])) |
|
| 124 | 124 | $bind_types .= 'd'; |
| 125 | 125 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 126 | 126 | else |
@@ -184,7 +184,7 @@ discard block |
||
| 184 | 184 | $this->numFields = $this->dbconn->field_count; |
| 185 | 185 | |
| 186 | 186 | if ($this->transac_mode) |
| 187 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 187 | + $this->transac_result = is_null($this->transac_result) ? $this->result : $this->transac_result && $this->result; |
|
| 188 | 188 | /* |
| 189 | 189 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
| 190 | 190 | * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -33,15 +33,17 @@ discard block |
||
| 33 | 33 | { |
| 34 | 34 | $this->driverName = 'Mysqli'; |
| 35 | 35 | |
| 36 | - if (!array_key_exists("dbchar", $options)) |
|
| 37 | - $options["dbchar"] = "utf8"; |
|
| 36 | + if (!array_key_exists("dbchar", $options)) { |
|
| 37 | + $options["dbchar"] = "utf8"; |
|
| 38 | + } |
|
| 38 | 39 | |
| 39 | 40 | parent::__construct($options); |
| 40 | 41 | |
| 41 | 42 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 42 | 43 | |
| 43 | - if ($auto_connect) |
|
| 44 | - $this->connect(); |
|
| 44 | + if ($auto_connect) { |
|
| 45 | + $this->connect(); |
|
| 46 | + } |
|
| 45 | 47 | } |
| 46 | 48 | |
| 47 | 49 | /** |
@@ -54,13 +56,15 @@ discard block |
||
| 54 | 56 | */ |
| 55 | 57 | public function connect() |
| 56 | 58 | { |
| 57 | - if (!extension_loaded('mysqli')) |
|
| 58 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 59 | + if (!extension_loaded('mysqli')) { |
|
| 60 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 61 | + } |
|
| 59 | 62 | |
| 60 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 62 | - else |
|
| 63 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 63 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 65 | + } else { |
|
| 66 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 67 | + } |
|
| 64 | 68 | |
| 65 | 69 | if ($conn->connect_errno) |
| 66 | 70 | { |
@@ -70,8 +74,7 @@ discard block |
||
| 70 | 74 | * the warning message "Property access is not allowed yet". |
| 71 | 75 | */ |
| 72 | 76 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
| 73 | - } |
|
| 74 | - else |
|
| 77 | + } else |
|
| 75 | 78 | { |
| 76 | 79 | $this->dbconn = $conn; |
| 77 | 80 | $this->dbconn->set_charset($this->dbchar); |
@@ -118,13 +121,15 @@ discard block |
||
| 118 | 121 | |
| 119 | 122 | for ($i = 0; $i < $n_params; $i++) |
| 120 | 123 | { |
| 121 | - if (is_string($param_values[$i])) |
|
| 122 | - $bind_types .= 's'; |
|
| 123 | - else if(is_float($param_values[$i])) |
|
| 124 | - $bind_types .= 'd'; |
|
| 124 | + if (is_string($param_values[$i])) { |
|
| 125 | + $bind_types .= 's'; |
|
| 126 | + } else if(is_float($param_values[$i])) { |
|
| 127 | + $bind_types .= 'd'; |
|
| 128 | + } |
|
| 125 | 129 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 126 | - else |
|
| 127 | - $bind_types .= 's'; |
|
| 130 | + else { |
|
| 131 | + $bind_types .= 's'; |
|
| 132 | + } |
|
| 128 | 133 | |
| 129 | 134 | $bind_values[] = '$param_values[' . $i . ']'; |
| 130 | 135 | } |
@@ -133,8 +138,7 @@ discard block |
||
| 133 | 138 | eval('$stmt->bind_param(\'' . $bind_types . '\', ' . $values . ');'); |
| 134 | 139 | |
| 135 | 140 | $r = $stmt->execute(); |
| 136 | - } |
|
| 137 | - else |
|
| 141 | + } else |
|
| 138 | 142 | { |
| 139 | 143 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
| 140 | 144 | |
@@ -163,28 +167,33 @@ discard block |
||
| 163 | 167 | * It is useful to prevent rollback transactions on insert statements because |
| 164 | 168 | * insert statement do not free results. |
| 165 | 169 | */ |
| 166 | - if ($res) |
|
| 167 | - $this->result = $res; |
|
| 170 | + if ($res) { |
|
| 171 | + $this->result = $res; |
|
| 172 | + } |
|
| 168 | 173 | } |
| 169 | 174 | |
| 170 | 175 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
| 171 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
| 172 | - $this->numRows = $this->result->num_rows; |
|
| 173 | - else |
|
| 176 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
| 177 | + $this->numRows = $this->result->num_rows; |
|
| 178 | + } else |
|
| 174 | 179 | { |
| 175 | - if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) |
|
| 176 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 180 | + if (property_exists($this->dbconn, 'affected_rows') && !$is_stmt_result) { |
|
| 181 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 182 | + } |
|
| 177 | 183 | } |
| 178 | 184 | |
| 179 | 185 | # affected_rows return the same of num_rows on select statements! |
| 180 | - if ($this->numRows > 0) |
|
| 181 | - $this->rowsAffected = 0; |
|
| 186 | + if ($this->numRows > 0) { |
|
| 187 | + $this->rowsAffected = 0; |
|
| 188 | + } |
|
| 182 | 189 | |
| 183 | - if (property_exists($this->dbconn, 'field_count')) |
|
| 184 | - $this->numFields = $this->dbconn->field_count; |
|
| 190 | + if (property_exists($this->dbconn, 'field_count')) { |
|
| 191 | + $this->numFields = $this->dbconn->field_count; |
|
| 192 | + } |
|
| 185 | 193 | |
| 186 | - if ($this->transac_mode) |
|
| 187 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 194 | + if ($this->transac_mode) { |
|
| 195 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 196 | + } |
|
| 188 | 197 | /* |
| 189 | 198 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
| 190 | 199 | * and TRUE for other successful queries, it should be handled to return only objects or resources. |
@@ -252,10 +261,10 @@ discard block |
||
| 252 | 261 | { |
| 253 | 262 | $data[] = $row; |
| 254 | 263 | } |
| 255 | - } |
|
| 256 | - else |
|
| 257 | - # This error is thrown because of 'execute' method has not been executed. |
|
| 264 | + } else { |
|
| 265 | + # This error is thrown because of 'execute' method has not been executed. |
|
| 258 | 266 | throw new \LogicException('There are not data in the buffer!'); |
| 267 | + } |
|
| 259 | 268 | |
| 260 | 269 | $this->arrayResult = $data; |
| 261 | 270 | |
@@ -270,7 +279,8 @@ discard block |
||
| 270 | 279 | public function __destruct() |
| 271 | 280 | { |
| 272 | 281 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 273 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 274 | - @$this->dbconn->close(); |
|
| 282 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 283 | + @$this->dbconn->close(); |
|
| 284 | + } |
|
| 275 | 285 | } |
| 276 | 286 | } |
| 277 | 287 | \ No newline at end of file |