@@ -298,8 +298,8 @@ |
||
| 298 | 298 | { |
| 299 | 299 | foreach ($options as $option => $value) |
| 300 | 300 | { |
| 301 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) |
|
| 302 | - $this->{'set'.$option}($value); |
|
| 301 | + if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set' . $option)) |
|
| 302 | + $this->{'set' . $option}($value); |
|
| 303 | 303 | } |
| 304 | 304 | } |
| 305 | 305 | |
@@ -209,8 +209,9 @@ discard block |
||
| 209 | 209 | */ |
| 210 | 210 | public function getArrayResult() |
| 211 | 211 | { |
| 212 | - if (!empty($this->arrayResult)) |
|
| 213 | - return $this->arrayResult; |
|
| 212 | + if (!empty($this->arrayResult)) { |
|
| 213 | + return $this->arrayResult; |
|
| 214 | + } |
|
| 214 | 215 | |
| 215 | 216 | return $this->toArray(); |
| 216 | 217 | } |
@@ -298,8 +299,9 @@ discard block |
||
| 298 | 299 | { |
| 299 | 300 | foreach ($options as $option => $value) |
| 300 | 301 | { |
| 301 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) |
|
| 302 | - $this->{'set'.$option}($value); |
|
| 302 | + if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) { |
|
| 303 | + $this->{'set'.$option}($value); |
|
| 304 | + } |
|
| 303 | 305 | } |
| 304 | 306 | } |
| 305 | 307 | |
@@ -343,8 +345,9 @@ discard block |
||
| 343 | 345 | */ |
| 344 | 346 | public function reconnect() |
| 345 | 347 | { |
| 346 | - if (!$this->isConnected()) |
|
| 347 | - throw new \LogicException("Connection was not established"); |
|
| 348 | + if (!$this->isConnected()) { |
|
| 349 | + throw new \LogicException("Connection was not established"); |
|
| 350 | + } |
|
| 348 | 351 | |
| 349 | 352 | $this->disconnect(); |
| 350 | 353 | return $this->connect(); |
@@ -373,8 +376,9 @@ discard block |
||
| 373 | 376 | */ |
| 374 | 377 | public function disconnect() |
| 375 | 378 | { |
| 376 | - if (!$this->isConnected()) |
|
| 377 | - throw new \LogicException("Connection was not established"); |
|
| 379 | + if (!$this->isConnected()) { |
|
| 380 | + throw new \LogicException("Connection was not established"); |
|
| 381 | + } |
|
| 378 | 382 | } |
| 379 | 383 | |
| 380 | 384 | /** |
@@ -386,11 +390,13 @@ discard block |
||
| 386 | 390 | */ |
| 387 | 391 | public function beginTransaction() |
| 388 | 392 | { |
| 389 | - if (!$this->isConnected()) |
|
| 390 | - $this->connect(); |
|
| 393 | + if (!$this->isConnected()) { |
|
| 394 | + $this->connect(); |
|
| 395 | + } |
|
| 391 | 396 | |
| 392 | - if ($this->transac_mode) |
|
| 393 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 397 | + if ($this->transac_mode) { |
|
| 398 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 399 | + } |
|
| 394 | 400 | |
| 395 | 401 | $this->transac_mode = true; |
| 396 | 402 | } |
@@ -404,16 +410,19 @@ discard block |
||
| 404 | 410 | */ |
| 405 | 411 | public function endTransaction() |
| 406 | 412 | { |
| 407 | - if (!$this->transac_mode) |
|
| 408 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 413 | + if (!$this->transac_mode) { |
|
| 414 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 415 | + } |
|
| 409 | 416 | |
| 410 | - if (is_null($this->transac_result)) |
|
| 411 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 417 | + if (is_null($this->transac_result)) { |
|
| 418 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 419 | + } |
|
| 412 | 420 | |
| 413 | - if ($this->transac_result) |
|
| 414 | - $this->commit(); |
|
| 415 | - else |
|
| 416 | - $this->rollback(); |
|
| 421 | + if ($this->transac_result) { |
|
| 422 | + $this->commit(); |
|
| 423 | + } else { |
|
| 424 | + $this->rollback(); |
|
| 425 | + } |
|
| 417 | 426 | |
| 418 | 427 | $this->result = $this->transac_result; |
| 419 | 428 | |
@@ -108,7 +108,7 @@ discard block |
||
| 108 | 108 | { |
| 109 | 109 | if (is_string($param_values[$i])) |
| 110 | 110 | $bind_types .= 's'; |
| 111 | - else if(is_float($param_values[$i])) |
|
| 111 | + else if (is_float($param_values[$i])) |
|
| 112 | 112 | $bind_types .= 'd'; |
| 113 | 113 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 114 | 114 | else |
@@ -164,7 +164,7 @@ discard block |
||
| 164 | 164 | $this->rowsAffected = $this->result->affected_rows; |
| 165 | 165 | |
| 166 | 166 | if ($this->transac_mode) |
| 167 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 167 | + $this->transac_result = is_null($this->transac_result) ? $this->result : $this->transac_result && $this->result; |
|
| 168 | 168 | |
| 169 | 169 | return $this->result; |
| 170 | 170 | } |
@@ -24,15 +24,17 @@ discard block |
||
| 24 | 24 | */ |
| 25 | 25 | public function __construct($options) |
| 26 | 26 | { |
| 27 | - if (!array_key_exists("dbchar", $options)) |
|
| 28 | - $options["dbchar"] = "utf8"; |
|
| 27 | + if (!array_key_exists("dbchar", $options)) { |
|
| 28 | + $options["dbchar"] = "utf8"; |
|
| 29 | + } |
|
| 29 | 30 | |
| 30 | 31 | parent::__construct($options); |
| 31 | 32 | |
| 32 | 33 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 33 | 34 | |
| 34 | - if ($auto_connect) |
|
| 35 | - $this->connect(); |
|
| 35 | + if ($auto_connect) { |
|
| 36 | + $this->connect(); |
|
| 37 | + } |
|
| 36 | 38 | } |
| 37 | 39 | |
| 38 | 40 | /** |
@@ -45,13 +47,15 @@ discard block |
||
| 45 | 47 | */ |
| 46 | 48 | public function connect() |
| 47 | 49 | { |
| 48 | - if (!extension_loaded('mysqli')) |
|
| 49 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 50 | + if (!extension_loaded('mysqli')) { |
|
| 51 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 52 | + } |
|
| 50 | 53 | |
| 51 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 52 | - $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 53 | - else |
|
| 54 | - $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 54 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 55 | + $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 56 | + } else { |
|
| 57 | + $this->dbconn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 58 | + } |
|
| 55 | 59 | |
| 56 | 60 | if ($this->dbconn->connect_errno) |
| 57 | 61 | { |
@@ -61,9 +65,9 @@ discard block |
||
| 61 | 65 | * the warning message "Property access is not allowed yet". |
| 62 | 66 | */ |
| 63 | 67 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
| 68 | + } else { |
|
| 69 | + $this->dbconn->set_charset($this->dbchar); |
|
| 64 | 70 | } |
| 65 | - else |
|
| 66 | - $this->dbconn->set_charset($this->dbchar); |
|
| 67 | 71 | |
| 68 | 72 | return $this->dbconn; |
| 69 | 73 | } |
@@ -106,13 +110,15 @@ discard block |
||
| 106 | 110 | |
| 107 | 111 | for ($i = 0; $i < $n_params; $i++) |
| 108 | 112 | { |
| 109 | - if (is_string($param_values[$i])) |
|
| 110 | - $bind_types .= 's'; |
|
| 111 | - else if(is_float($param_values[$i])) |
|
| 112 | - $bind_types .= 'd'; |
|
| 113 | + if (is_string($param_values[$i])) { |
|
| 114 | + $bind_types .= 's'; |
|
| 115 | + } else if(is_float($param_values[$i])) { |
|
| 116 | + $bind_types .= 'd'; |
|
| 117 | + } |
|
| 113 | 118 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 114 | - else |
|
| 115 | - $bind_types .= 's'; |
|
| 119 | + else { |
|
| 120 | + $bind_types .= 's'; |
|
| 121 | + } |
|
| 116 | 122 | |
| 117 | 123 | $bind_values[] = '$param_values[' . $i . ']'; |
| 118 | 124 | } |
@@ -133,12 +139,12 @@ discard block |
||
| 133 | 139 | * It is useful to prevent rollback transactions on insert statements because |
| 134 | 140 | * insert statement do not free results. |
| 135 | 141 | */ |
| 136 | - if ($res) |
|
| 137 | - $this->result = $res; |
|
| 142 | + if ($res) { |
|
| 143 | + $this->result = $res; |
|
| 144 | + } |
|
| 138 | 145 | } |
| 139 | 146 | } |
| 140 | - } |
|
| 141 | - else |
|
| 147 | + } else |
|
| 142 | 148 | { |
| 143 | 149 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
| 144 | 150 | |
@@ -154,17 +160,21 @@ discard block |
||
| 154 | 160 | throw new Exception\InvalidQueryException($this->dbconn->error, $this->dbconn->errno); |
| 155 | 161 | } |
| 156 | 162 | |
| 157 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
| 158 | - $this->numRows = $this->result->num_rows; |
|
| 163 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
| 164 | + $this->numRows = $this->result->num_rows; |
|
| 165 | + } |
|
| 159 | 166 | |
| 160 | - if (is_object($this->result) && property_exists($this->result, 'field_count')) |
|
| 161 | - $this->numFields = $this->result->field_count; |
|
| 167 | + if (is_object($this->result) && property_exists($this->result, 'field_count')) { |
|
| 168 | + $this->numFields = $this->result->field_count; |
|
| 169 | + } |
|
| 162 | 170 | |
| 163 | - if (is_object($this->result) && property_exists($this->result, 'affected_rows')) |
|
| 164 | - $this->rowsAffected = $this->result->affected_rows; |
|
| 171 | + if (is_object($this->result) && property_exists($this->result, 'affected_rows')) { |
|
| 172 | + $this->rowsAffected = $this->result->affected_rows; |
|
| 173 | + } |
|
| 165 | 174 | |
| 166 | - if ($this->transac_mode) |
|
| 167 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 175 | + if ($this->transac_mode) { |
|
| 176 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 177 | + } |
|
| 168 | 178 | |
| 169 | 179 | return $this->result; |
| 170 | 180 | } |
@@ -220,9 +230,8 @@ discard block |
||
| 220 | 230 | { |
| 221 | 231 | $data[] = $row; |
| 222 | 232 | } |
| 223 | - } |
|
| 224 | - else |
|
| 225 | - /* |
|
| 233 | + } else { |
|
| 234 | + /* |
|
| 226 | 235 | * "This kind of exception should lead directly to a fix in your code" |
| 227 | 236 | * So much production tests tell us this error is throwed because developers |
| 228 | 237 | * execute toArray() before execute(). |
@@ -230,6 +239,7 @@ discard block |
||
| 230 | 239 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 231 | 240 | */ |
| 232 | 241 | throw new \LogicException('There are not data in the buffer!'); |
| 242 | + } |
|
| 233 | 243 | |
| 234 | 244 | $this->arrayResult = $data; |
| 235 | 245 | |
@@ -244,7 +254,8 @@ discard block |
||
| 244 | 254 | public function __destruct() |
| 245 | 255 | { |
| 246 | 256 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 247 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 248 | - @$this->dbconn->close(); |
|
| 257 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 258 | + @$this->dbconn->close(); |
|
| 259 | + } |
|
| 249 | 260 | } |
| 250 | 261 | } |
| 251 | 262 | \ No newline at end of file |
@@ -85,13 +85,14 @@ discard block |
||
| 85 | 85 | "Sqlsrv" => "Drone\Db\Driver\SQLServer", |
| 86 | 86 | ]; |
| 87 | 87 | |
| 88 | - if (gettype($connection_identifier) == 'array') |
|
| 89 | - $connection_array = $connection_identifier; |
|
| 90 | - else |
|
| 88 | + if (gettype($connection_identifier) == 'array') { |
|
| 89 | + $connection_array = $connection_identifier; |
|
| 90 | + } else |
|
| 91 | 91 | { |
| 92 | 92 | # Take connection parameters from configuration file |
| 93 | - if (!file_exists("config/database.config.php")) |
|
| 94 | - throw new \RuntimeException("config/data.base.config.php is missing!"); |
|
| 93 | + if (!file_exists("config/database.config.php")) { |
|
| 94 | + throw new \RuntimeException("config/data.base.config.php is missing!"); |
|
| 95 | + } |
|
| 95 | 96 | |
| 96 | 97 | $dbsettings = include("config/database.config.php"); |
| 97 | 98 | $connection_array = $dbsettings[$connection_identifier]; |
@@ -106,8 +107,8 @@ discard block |
||
| 106 | 107 | |
| 107 | 108 | $this->driverName = $drv; |
| 108 | 109 | $this->db = new $driver[$drv]($connection_array); |
| 110 | + } else { |
|
| 111 | + throw new \RuntimeException("The Database driver does not exists"); |
|
| 109 | 112 | } |
| 110 | - else |
|
| 111 | - throw new \RuntimeException("The Database driver does not exists"); |
|
| 112 | 113 | } |
| 113 | 114 | } |
| 114 | 115 | \ No newline at end of file |
@@ -77,8 +77,9 @@ |
||
| 77 | 77 | |
| 78 | 78 | foreach ($arguments as $key => $arg) |
| 79 | 79 | { |
| 80 | - if (is_string($arg)) |
|
| 81 | - $arguments[$key] = "'$arg'"; |
|
| 80 | + if (is_string($arg)) { |
|
| 81 | + $arguments[$key] = "'$arg'"; |
|
| 82 | + } |
|
| 82 | 83 | } |
| 83 | 84 | |
| 84 | 85 | $arguments = implode(", ", array_values($arguments)); |
@@ -22,14 +22,14 @@ discard block |
||
| 22 | 22 | * |
| 23 | 23 | * @param array $where |
| 24 | 24 | */ |
| 25 | - public function select(Array $where); |
|
| 25 | + public function select(Array $where); |
|
| 26 | 26 | |
| 27 | 27 | /** |
| 28 | 28 | * Insert statement |
| 29 | 29 | * |
| 30 | 30 | * @param array $data |
| 31 | 31 | */ |
| 32 | - public function insert(Array $data); |
|
| 32 | + public function insert(Array $data); |
|
| 33 | 33 | |
| 34 | 34 | /** |
| 35 | 35 | * Update statement |
@@ -37,12 +37,12 @@ discard block |
||
| 37 | 37 | * @param array $set |
| 38 | 38 | * @param array $where |
| 39 | 39 | */ |
| 40 | - public function update(Array $set, Array $where); |
|
| 40 | + public function update(Array $set, Array $where); |
|
| 41 | 41 | |
| 42 | 42 | /** |
| 43 | 43 | * Delete statement |
| 44 | 44 | * |
| 45 | 45 | * @param array $where |
| 46 | 46 | */ |
| 47 | - public function delete(Array $where); |
|
| 47 | + public function delete(Array $where); |
|
| 48 | 48 | } |
| 49 | 49 | \ No newline at end of file |
@@ -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 |
@@ -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 | } |
@@ -93,24 +93,24 @@ discard block |
||
| 93 | 93 | { |
| 94 | 94 | foreach ($contents as $i) |
| 95 | 95 | { |
| 96 | - if (is_file($handler.'/'.$i)) |
|
| 96 | + if (is_file($handler . '/' . $i)) |
|
| 97 | 97 | { |
| 98 | - $allContents[] = $handler.'/'.$i; |
|
| 98 | + $allContents[] = $handler . '/' . $i; |
|
| 99 | 99 | |
| 100 | - $this->buffer = $handler.'/'.$i; |
|
| 100 | + $this->buffer = $handler . '/' . $i; |
|
| 101 | 101 | call_user_func($fileCallback, $this); |
| 102 | 102 | } |
| 103 | - elseif (is_dir($handler.'/'.$i)) |
|
| 103 | + elseif (is_dir($handler . '/' . $i)) |
|
| 104 | 104 | { |
| 105 | - $allContents[] = $handler.'/'.$i; |
|
| 105 | + $allContents[] = $handler . '/' . $i; |
|
| 106 | 106 | |
| 107 | - $this->buffer = $handler.'/'.$i; |
|
| 108 | - $this->getContents($handler.'/'.$i, $fileCallback, $dirCallback); |
|
| 107 | + $this->buffer = $handler . '/' . $i; |
|
| 108 | + $this->getContents($handler . '/' . $i, $fileCallback, $dirCallback); |
|
| 109 | 109 | |
| 110 | 110 | $directory = scandir($handler); |
| 111 | 111 | |
| 112 | 112 | if (!count($directory) < 3) |
| 113 | - $this->buffer = $handler.'/'.$i; |
|
| 113 | + $this->buffer = $handler . '/' . $i; |
|
| 114 | 114 | |
| 115 | 115 | call_user_func($dirCallback, $this); |
| 116 | 116 | } |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | if (!empty($path)) |
| 197 | 197 | if (!strlen(stristr($item, $path)) > 0) |
| 198 | 198 | continue; |
| 199 | - if (strstr($item,'~') === false && $item != '.' && $item != '..') |
|
| 199 | + if (strstr($item, '~') === false && $item != '.' && $item != '..') |
|
| 200 | 200 | $filesToReturn[] = $item; |
| 201 | 201 | } |
| 202 | 202 | } |
@@ -299,7 +299,7 @@ discard block |
||
| 299 | 299 | if (is_dir($dest)) |
| 300 | 300 | { |
| 301 | 301 | if (!$recursive) |
| 302 | - copy($file, $dest.'/'.$file); |
|
| 302 | + copy($file, $dest . '/' . $file); |
|
| 303 | 303 | else { |
| 304 | 304 | |
| 305 | 305 | $files = array(); |
@@ -318,14 +318,14 @@ discard block |
||
| 318 | 318 | |
| 319 | 319 | foreach ($files[1] as $item) |
| 320 | 320 | { |
| 321 | - if (!file_exists($dest.'/'.$item)) |
|
| 321 | + if (!file_exists($dest . '/' . $item)) |
|
| 322 | 322 | mkdir("$dest/$item", 0777, true); |
| 323 | 323 | } |
| 324 | 324 | |
| 325 | 325 | foreach ($files[0] as $item) |
| 326 | 326 | { |
| 327 | 327 | if (!file_exists("$dest/$files")) |
| 328 | - copy($item, $dest.'/'.$item); |
|
| 328 | + copy($item, $dest . '/' . $item); |
|
| 329 | 329 | } |
| 330 | 330 | }); |
| 331 | 331 | } |
@@ -350,12 +350,12 @@ discard block |
||
| 350 | 350 | throw new Exception("Missing parameter for mv!"); |
| 351 | 351 | |
| 352 | 352 | if (is_dir($newfile)) |
| 353 | - $newfile .= '/'.basename($oldfile); |
|
| 353 | + $newfile .= '/' . basename($oldfile); |
|
| 354 | 354 | |
| 355 | 355 | if ($oldfile == $newfile) |
| 356 | 356 | throw new Exception("'$oldfile' and '$newfile' are the same file"); |
| 357 | 357 | |
| 358 | - if(!rename($oldfile, $newfile)) |
|
| 358 | + if (!rename($oldfile, $newfile)) |
|
| 359 | 359 | return false; |
| 360 | 360 | |
| 361 | 361 | return true; |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | else { |
| 386 | 386 | if (!is_dir($dir)) |
| 387 | 387 | { |
| 388 | - if(!mkdir("$dir", 0777)) |
|
| 388 | + if (!mkdir("$dir", 0777)) |
|
| 389 | 389 | return false; |
| 390 | 390 | } |
| 391 | 391 | } |
@@ -83,8 +83,9 @@ discard block |
||
| 83 | 83 | |
| 84 | 84 | foreach ($filesForHandler as $item) |
| 85 | 85 | { |
| 86 | - if ($item != '.' && $item != '..') |
|
| 87 | - $contents[] = $item; |
|
| 86 | + if ($item != '.' && $item != '..') { |
|
| 87 | + $contents[] = $item; |
|
| 88 | + } |
|
| 88 | 89 | } |
| 89 | 90 | |
| 90 | 91 | $allContents = $contents; |
@@ -99,8 +100,7 @@ discard block |
||
| 99 | 100 | |
| 100 | 101 | $this->buffer = $handler.'/'.$i; |
| 101 | 102 | call_user_func($fileCallback, $this); |
| 102 | - } |
|
| 103 | - elseif (is_dir($handler.'/'.$i)) |
|
| 103 | + } elseif (is_dir($handler.'/'.$i)) |
|
| 104 | 104 | { |
| 105 | 105 | $allContents[] = $handler.'/'.$i; |
| 106 | 106 | |
@@ -109,19 +109,21 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | $directory = scandir($handler); |
| 111 | 111 | |
| 112 | - if (!count($directory) < 3) |
|
| 113 | - $this->buffer = $handler.'/'.$i; |
|
| 112 | + if (!count($directory) < 3) { |
|
| 113 | + $this->buffer = $handler.'/'.$i; |
|
| 114 | + } |
|
| 114 | 115 | |
| 115 | 116 | call_user_func($dirCallback, $this); |
| 116 | 117 | } |
| 117 | 118 | } |
| 118 | 119 | } |
| 120 | + } else { |
|
| 121 | + throw new Exception("The directory '$handler' does not exists"); |
|
| 119 | 122 | } |
| 120 | - else |
|
| 121 | - throw new Exception("The directory '$handler' does not exists"); |
|
| 122 | 123 | |
| 123 | - if (!is_null($callback)) |
|
| 124 | - call_user_func($callback, $this); |
|
| 124 | + if (!is_null($callback)) { |
|
| 125 | + call_user_func($callback, $this); |
|
| 126 | + } |
|
| 125 | 127 | |
| 126 | 128 | return $allContents; |
| 127 | 129 | } |
@@ -133,10 +135,11 @@ discard block |
||
| 133 | 135 | */ |
| 134 | 136 | public function pwd() |
| 135 | 137 | { |
| 136 | - if (getcwd()) |
|
| 137 | - $this->buffer = getcwd(); |
|
| 138 | - else |
|
| 139 | - return false; |
|
| 138 | + if (getcwd()) { |
|
| 139 | + $this->buffer = getcwd(); |
|
| 140 | + } else { |
|
| 141 | + return false; |
|
| 142 | + } |
|
| 140 | 143 | |
| 141 | 144 | return $this->buffer; |
| 142 | 145 | } |
@@ -155,9 +158,9 @@ discard block |
||
| 155 | 158 | |
| 156 | 159 | $path = (is_null($path) || empty($path)) ? '.' : $path; |
| 157 | 160 | |
| 158 | - if (is_file($path)) |
|
| 159 | - $filesToReturn = array($path); |
|
| 160 | - elseif (is_dir($path)) |
|
| 161 | + if (is_file($path)) { |
|
| 162 | + $filesToReturn = array($path); |
|
| 163 | + } elseif (is_dir($path)) |
|
| 161 | 164 | { |
| 162 | 165 | $pathIns = dir($path); |
| 163 | 166 | |
@@ -179,25 +182,25 @@ discard block |
||
| 179 | 182 | foreach ($files as $item) { |
| 180 | 183 | $filesToReturn[] = $item; |
| 181 | 184 | } |
| 182 | - } |
|
| 183 | - else { |
|
| 185 | + } else { |
|
| 184 | 186 | while (false !== ($item = $pathIns->read())) { |
| 185 | 187 | $filesToReturn[] = $item; |
| 186 | 188 | } |
| 187 | 189 | $pathIns->close(); |
| 188 | 190 | } |
| 189 | - } |
|
| 190 | - else { |
|
| 191 | + } else { |
|
| 191 | 192 | |
| 192 | 193 | $contents = $this->ls(); |
| 193 | 194 | |
| 194 | 195 | foreach ($contents as $item) |
| 195 | 196 | { |
| 196 | - if (!empty($path)) |
|
| 197 | - if (!strlen(stristr($item, $path)) > 0) |
|
| 197 | + if (!empty($path)) { |
|
| 198 | + if (!strlen(stristr($item, $path)) > 0) |
|
| 198 | 199 | continue; |
| 199 | - if (strstr($item,'~') === false && $item != '.' && $item != '..') |
|
| 200 | - $filesToReturn[] = $item; |
|
| 200 | + } |
|
| 201 | + if (strstr($item,'~') === false && $item != '.' && $item != '..') { |
|
| 202 | + $filesToReturn[] = $item; |
|
| 203 | + } |
|
| 201 | 204 | } |
| 202 | 205 | } |
| 203 | 206 | |
@@ -217,8 +220,9 @@ discard block |
||
| 217 | 220 | |
| 218 | 221 | if (is_dir($path)) |
| 219 | 222 | { |
| 220 | - if (chdir($moveTo)) |
|
| 221 | - return true; |
|
| 223 | + if (chdir($moveTo)) { |
|
| 224 | + return true; |
|
| 225 | + } |
|
| 222 | 226 | } |
| 223 | 227 | |
| 224 | 228 | return false; |
@@ -235,11 +239,13 @@ discard block |
||
| 235 | 239 | { |
| 236 | 240 | if (file_exists($file)) |
| 237 | 241 | { |
| 238 | - if (!$openFile = fopen($file, 'w+')) |
|
| 239 | - return false; |
|
| 242 | + if (!$openFile = fopen($file, 'w+')) { |
|
| 243 | + return false; |
|
| 244 | + } |
|
| 240 | 245 | |
| 241 | - if (fwrite($openFile, "")) |
|
| 242 | - return true; |
|
| 246 | + if (fwrite($openFile, "")) { |
|
| 247 | + return true; |
|
| 248 | + } |
|
| 243 | 249 | |
| 244 | 250 | fclose($openFile); |
| 245 | 251 | } |
@@ -259,12 +265,13 @@ discard block |
||
| 259 | 265 | { |
| 260 | 266 | $recursive = is_null($recursive) ? false : $recursive; |
| 261 | 267 | |
| 262 | - if (is_null($file)) |
|
| 263 | - throw new Exception("Missing parameter for rm!"); |
|
| 268 | + if (is_null($file)) { |
|
| 269 | + throw new Exception("Missing parameter for rm!"); |
|
| 270 | + } |
|
| 264 | 271 | |
| 265 | - if (file_exists($file) && !$recursive) |
|
| 266 | - unlink($file); |
|
| 267 | - elseif (is_dir($file) && $recursive) |
|
| 272 | + if (file_exists($file) && !$recursive) { |
|
| 273 | + unlink($file); |
|
| 274 | + } elseif (is_dir($file) && $recursive) |
|
| 268 | 275 | { |
| 269 | 276 | $that = $this; |
| 270 | 277 | |
@@ -293,14 +300,15 @@ discard block |
||
| 293 | 300 | { |
| 294 | 301 | $recursive = (is_null($recursive)) ? false : $recursive; |
| 295 | 302 | |
| 296 | - if (empty($file) || empty($dest)) |
|
| 297 | - throw new Exception("Missing parameters!"); |
|
| 303 | + if (empty($file) || empty($dest)) { |
|
| 304 | + throw new Exception("Missing parameters!"); |
|
| 305 | + } |
|
| 298 | 306 | |
| 299 | 307 | if (is_dir($dest)) |
| 300 | 308 | { |
| 301 | - if (!$recursive) |
|
| 302 | - copy($file, $dest.'/'.$file); |
|
| 303 | - else { |
|
| 309 | + if (!$recursive) { |
|
| 310 | + copy($file, $dest.'/'.$file); |
|
| 311 | + } else { |
|
| 304 | 312 | |
| 305 | 313 | $files = array(); |
| 306 | 314 | $files[0] = array(); |
@@ -318,20 +326,22 @@ discard block |
||
| 318 | 326 | |
| 319 | 327 | foreach ($files[1] as $item) |
| 320 | 328 | { |
| 321 | - if (!file_exists($dest.'/'.$item)) |
|
| 322 | - mkdir("$dest/$item", 0777, true); |
|
| 329 | + if (!file_exists($dest.'/'.$item)) { |
|
| 330 | + mkdir("$dest/$item", 0777, true); |
|
| 331 | + } |
|
| 323 | 332 | } |
| 324 | 333 | |
| 325 | 334 | foreach ($files[0] as $item) |
| 326 | 335 | { |
| 327 | - if (!file_exists("$dest/$files")) |
|
| 328 | - copy($item, $dest.'/'.$item); |
|
| 336 | + if (!file_exists("$dest/$files")) { |
|
| 337 | + copy($item, $dest.'/'.$item); |
|
| 338 | + } |
|
| 329 | 339 | } |
| 330 | 340 | }); |
| 331 | 341 | } |
| 342 | + } else { |
|
| 343 | + copy($file, $dest); |
|
| 332 | 344 | } |
| 333 | - else |
|
| 334 | - copy($file, $dest); |
|
| 335 | 345 | |
| 336 | 346 | return true; |
| 337 | 347 | } |
@@ -346,17 +356,21 @@ discard block |
||
| 346 | 356 | */ |
| 347 | 357 | public function mv($oldfile, $newfile) |
| 348 | 358 | { |
| 349 | - if (empty($oldfile)) |
|
| 350 | - throw new Exception("Missing parameter for mv!"); |
|
| 359 | + if (empty($oldfile)) { |
|
| 360 | + throw new Exception("Missing parameter for mv!"); |
|
| 361 | + } |
|
| 351 | 362 | |
| 352 | - if (is_dir($newfile)) |
|
| 353 | - $newfile .= '/'.basename($oldfile); |
|
| 363 | + if (is_dir($newfile)) { |
|
| 364 | + $newfile .= '/'.basename($oldfile); |
|
| 365 | + } |
|
| 354 | 366 | |
| 355 | - if ($oldfile == $newfile) |
|
| 356 | - throw new Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 367 | + if ($oldfile == $newfile) { |
|
| 368 | + throw new Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 369 | + } |
|
| 357 | 370 | |
| 358 | - if(!rename($oldfile, $newfile)) |
|
| 359 | - return false; |
|
| 371 | + if(!rename($oldfile, $newfile)) { |
|
| 372 | + return false; |
|
| 373 | + } |
|
| 360 | 374 | |
| 361 | 375 | return true; |
| 362 | 376 | } |
@@ -372,21 +386,24 @@ discard block |
||
| 372 | 386 | */ |
| 373 | 387 | public function mkdir($dir, $dest = null, $recursive = null) |
| 374 | 388 | { |
| 375 | - if (empty($dir)) |
|
| 376 | - throw new Exception("Missing parameter for mkdir!"); |
|
| 389 | + if (empty($dir)) { |
|
| 390 | + throw new Exception("Missing parameter for mkdir!"); |
|
| 391 | + } |
|
| 377 | 392 | |
| 378 | - if (empty($dest)) |
|
| 379 | - $dest = '.'; |
|
| 393 | + if (empty($dest)) { |
|
| 394 | + $dest = '.'; |
|
| 395 | + } |
|
| 380 | 396 | |
| 381 | 397 | $recursive = (is_null($recursive)) ? false : $recursive; |
| 382 | 398 | |
| 383 | - if ($recursive) |
|
| 384 | - mkdir("$dest/$dir", 0777, true); |
|
| 385 | - else { |
|
| 399 | + if ($recursive) { |
|
| 400 | + mkdir("$dest/$dir", 0777, true); |
|
| 401 | + } else { |
|
| 386 | 402 | if (!is_dir($dir)) |
| 387 | 403 | { |
| 388 | - if(!mkdir("$dir", 0777)) |
|
| 389 | - return false; |
|
| 404 | + if(!mkdir("$dir", 0777)) { |
|
| 405 | + return false; |
|
| 406 | + } |
|
| 390 | 407 | } |
| 391 | 408 | } |
| 392 | 409 | return true; |
@@ -401,12 +418,14 @@ discard block |
||
| 401 | 418 | */ |
| 402 | 419 | public function rmdir($dir) |
| 403 | 420 | { |
| 404 | - if (is_null($dir) || empty($dir)) |
|
| 405 | - throw new Exception("Missing parameter for rmdir!"); |
|
| 421 | + if (is_null($dir) || empty($dir)) { |
|
| 422 | + throw new Exception("Missing parameter for rmdir!"); |
|
| 423 | + } |
|
| 406 | 424 | |
| 407 | - if (rmdir($dir)) |
|
| 408 | - return true; |
|
| 409 | - else |
|
| 410 | - return false; |
|
| 425 | + if (rmdir($dir)) { |
|
| 426 | + return true; |
|
| 427 | + } else { |
|
| 428 | + return false; |
|
| 429 | + } |
|
| 411 | 430 | } |
| 412 | 431 | } |
| 413 | 432 | \ No newline at end of file |
@@ -116,7 +116,7 @@ discard block |
||
| 116 | 116 | $exec = sqlsrv_execute($stmt); |
| 117 | 117 | } |
| 118 | 118 | else |
| 119 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
| 119 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array("Scrollable" => SQLSRV_CURSOR_KEYSET)); |
|
| 120 | 120 | |
| 121 | 121 | if ($exec === false) |
| 122 | 122 | { |
@@ -137,7 +137,7 @@ discard block |
||
| 137 | 137 | $this->rowsAffected = sqlsrv_rows_affected($this->result); |
| 138 | 138 | |
| 139 | 139 | if ($this->transac_mode) |
| 140 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 140 | + $this->transac_result = is_null($this->transac_result) ? $this->result : $this->transac_result && $this->result; |
|
| 141 | 141 | |
| 142 | 142 | return $this->result; |
| 143 | 143 | } |
@@ -31,15 +31,17 @@ discard block |
||
| 31 | 31 | */ |
| 32 | 32 | public function __construct($options) |
| 33 | 33 | { |
| 34 | - if (!array_key_exists("dbchar", $options)) |
|
| 35 | - $options["dbchar"] = "UTF-8"; |
|
| 34 | + if (!array_key_exists("dbchar", $options)) { |
|
| 35 | + $options["dbchar"] = "UTF-8"; |
|
| 36 | + } |
|
| 36 | 37 | |
| 37 | 38 | parent::__construct($options); |
| 38 | 39 | |
| 39 | 40 | $auto_connect = array_key_exists('auto_connect', $options) ? $options["auto_connect"] : true; |
| 40 | 41 | |
| 41 | - if ($auto_connect) |
|
| 42 | - $this->connect(); |
|
| 42 | + if ($auto_connect) { |
|
| 43 | + $this->connect(); |
|
| 44 | + } |
|
| 43 | 45 | } |
| 44 | 46 | |
| 45 | 47 | /** |
@@ -52,11 +54,13 @@ discard block |
||
| 52 | 54 | */ |
| 53 | 55 | public function connect() |
| 54 | 56 | { |
| 55 | - if (!extension_loaded('sqlsrv')) |
|
| 56 | - throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
| 57 | + if (!extension_loaded('sqlsrv')) { |
|
| 58 | + throw new \RuntimeException("The Sqlsrv extension is not loaded"); |
|
| 59 | + } |
|
| 57 | 60 | |
| 58 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 59 | - $this->dbhost .= ', ' . $this->dbport; |
|
| 61 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 62 | + $this->dbhost .= ', ' . $this->dbport; |
|
| 63 | + } |
|
| 60 | 64 | |
| 61 | 65 | $db_info = array("Database" => $this->dbname, "UID" => $this->dbuser, "PWD" => $this->dbpass, "CharacterSet" => $this->dbchar); |
| 62 | 66 | $conn = sqlsrv_connect($this->dbhost, $db_info); |
@@ -116,9 +120,9 @@ discard block |
||
| 116 | 120 | } |
| 117 | 121 | |
| 118 | 122 | $exec = sqlsrv_execute($stmt); |
| 123 | + } else { |
|
| 124 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
| 119 | 125 | } |
| 120 | - else |
|
| 121 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
| 122 | 126 | |
| 123 | 127 | if ($exec === false) |
| 124 | 128 | { |
@@ -138,8 +142,9 @@ discard block |
||
| 138 | 142 | $this->numFields = sqlsrv_num_fields($this->result); |
| 139 | 143 | $this->rowsAffected = sqlsrv_rows_affected($this->result); |
| 140 | 144 | |
| 141 | - if ($this->transac_mode) |
|
| 142 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 145 | + if ($this->transac_mode) { |
|
| 146 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 147 | + } |
|
| 143 | 148 | |
| 144 | 149 | return $this->result; |
| 145 | 150 | } |
@@ -206,9 +211,8 @@ discard block |
||
| 206 | 211 | { |
| 207 | 212 | $data[] = $row; |
| 208 | 213 | } |
| 209 | - } |
|
| 210 | - else |
|
| 211 | - /* |
|
| 214 | + } else { |
|
| 215 | + /* |
|
| 212 | 216 | * "This kind of exception should lead directly to a fix in your code" |
| 213 | 217 | * So much production tests tell us this error is throwed because developers |
| 214 | 218 | * execute toArray() before execute(). |
@@ -216,6 +220,7 @@ discard block |
||
| 216 | 220 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 217 | 221 | */ |
| 218 | 222 | throw new \LogicException('There are not data in the buffer!'); |
| 223 | + } |
|
| 219 | 224 | |
| 220 | 225 | $this->arrayResult = $data; |
| 221 | 226 | |
@@ -229,7 +234,8 @@ discard block |
||
| 229 | 234 | */ |
| 230 | 235 | public function __destruct() |
| 231 | 236 | { |
| 232 | - if ($this->dbconn) |
|
| 233 | - sqlsrv_close($this->dbconn); |
|
| 237 | + if ($this->dbconn) { |
|
| 238 | + sqlsrv_close($this->dbconn); |
|
| 239 | + } |
|
| 234 | 240 | } |
| 235 | 241 | } |
| 236 | 242 | \ No newline at end of file |