@@ -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); |
@@ -137,13 +141,13 @@ discard block |
||
| 137 | 141 | } |
| 138 | 142 | |
| 139 | 143 | $exec = sqlsrv_execute($stmt); |
| 140 | - } |
|
| 141 | - else |
|
| 144 | + } else |
|
| 142 | 145 | { |
| 143 | - if ($isSelectStm) |
|
| 144 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
| 145 | - else |
|
| 146 | - $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
| 146 | + if ($isSelectStm) { |
|
| 147 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params, array( "Scrollable" => SQLSRV_CURSOR_KEYSET )); |
|
| 148 | + } else { |
|
| 149 | + $exec = $this->result = sqlsrv_query($this->dbconn, $sql, $params); |
|
| 150 | + } |
|
| 147 | 151 | } |
| 148 | 152 | |
| 149 | 153 | if ($exec === false) |
@@ -163,11 +167,13 @@ discard block |
||
| 163 | 167 | $this->numRows = sqlsrv_has_rows($this->result) ? sqlsrv_num_rows($this->result) : $this->numRows; |
| 164 | 168 | $this->numFields = sqlsrv_num_fields($this->result); |
| 165 | 169 | |
| 166 | - if ($isInsertStm || $isUpdateStm || $isDeleteStm) |
|
| 167 | - $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
| 170 | + if ($isInsertStm || $isUpdateStm || $isDeleteStm) { |
|
| 171 | + $this->rowsAffected = sqlsrv_rows_affected($this->result); |
|
| 172 | + } |
|
| 168 | 173 | |
| 169 | - if ($this->transac_mode) |
|
| 170 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 174 | + if ($this->transac_mode) { |
|
| 175 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 176 | + } |
|
| 171 | 177 | |
| 172 | 178 | return $this->result; |
| 173 | 179 | } |
@@ -234,9 +240,8 @@ discard block |
||
| 234 | 240 | { |
| 235 | 241 | $data[] = $row; |
| 236 | 242 | } |
| 237 | - } |
|
| 238 | - else |
|
| 239 | - /* |
|
| 243 | + } else { |
|
| 244 | + /* |
|
| 240 | 245 | * "This kind of exception should lead directly to a fix in your code" |
| 241 | 246 | * So much production tests tell us this error is throwed because developers |
| 242 | 247 | * execute toArray() before execute(). |
@@ -244,6 +249,7 @@ discard block |
||
| 244 | 249 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 245 | 250 | */ |
| 246 | 251 | throw new \LogicException('There are not data in the buffer!'); |
| 252 | + } |
|
| 247 | 253 | |
| 248 | 254 | $this->arrayResult = $data; |
| 249 | 255 | |
@@ -257,7 +263,8 @@ discard block |
||
| 257 | 263 | */ |
| 258 | 264 | public function __destruct() |
| 259 | 265 | { |
| 260 | - if ($this->dbconn) |
|
| 261 | - sqlsrv_close($this->dbconn); |
|
| 266 | + if ($this->dbconn) { |
|
| 267 | + sqlsrv_close($this->dbconn); |
|
| 268 | + } |
|
| 262 | 269 | } |
| 263 | 270 | } |
| 264 | 271 | \ No newline at end of file |
@@ -58,8 +58,9 @@ discard block |
||
| 58 | 58 | public function prepare() |
| 59 | 59 | { |
| 60 | 60 | # start sessions |
| 61 | - if (!isset($_SESSION)) |
|
| 62 | - session_start(); |
|
| 61 | + if (!isset($_SESSION)) { |
|
| 62 | + session_start(); |
|
| 63 | + } |
|
| 63 | 64 | } |
| 64 | 65 | |
| 65 | 66 | /** |
@@ -91,8 +92,7 @@ discard block |
||
| 91 | 92 | |
| 92 | 93 | // Best way to view all possible errors |
| 93 | 94 | error_reporting(-1); |
| 94 | - } |
|
| 95 | - else { |
|
| 95 | + } else { |
|
| 96 | 96 | ini_set('display_errors', 0); |
| 97 | 97 | error_reporting(-1); |
| 98 | 98 | } |
@@ -109,10 +109,11 @@ discard block |
||
| 109 | 109 | |
| 110 | 110 | foreach ($app_config_file["router"]["routes"] as $name => $route) |
| 111 | 111 | { |
| 112 | - if ($route instanceof \Zend\Router\Http\RouteInterface) |
|
| 113 | - $this->getRouter()->addZendRoute($name, $route); |
|
| 114 | - else |
|
| 115 | - $this->getRouter()->addRoute($route); |
|
| 112 | + if ($route instanceof \Zend\Router\Http\RouteInterface) { |
|
| 113 | + $this->getRouter()->addZendRoute($name, $route); |
|
| 114 | + } else { |
|
| 115 | + $this->getRouter()->addRoute($route); |
|
| 116 | + } |
|
| 116 | 117 | } |
| 117 | 118 | } |
| 118 | 119 | |
@@ -146,14 +147,15 @@ discard block |
||
| 146 | 147 | * This instruction include each module declared in application.config.php |
| 147 | 148 | * Each module has an autoloader to load its classes (controllers and models) |
| 148 | 149 | */ |
| 149 | - if (file_exists("module/".$module."/Module.php")) |
|
| 150 | - include("module/".$module."/Module.php"); |
|
| 150 | + if (file_exists("module/".$module."/Module.php")) { |
|
| 151 | + include("module/".$module."/Module.php"); |
|
| 152 | + } |
|
| 151 | 153 | |
| 152 | 154 | spl_autoload_register($module . "\Module::loader"); |
| 153 | 155 | } |
| 156 | + } else { |
|
| 157 | + throw new \RuntimeException("The application must have at least one module"); |
|
| 154 | 158 | } |
| 155 | - else |
|
| 156 | - throw new \RuntimeException("The application must have at least one module"); |
|
| 157 | 159 | } |
| 158 | 160 | |
| 159 | 161 | /** |
@@ -175,8 +177,9 @@ discard block |
||
| 175 | 177 | $uri .= !empty($controller) ? '/' . $controller : ""; |
| 176 | 178 | $uri .= !empty($view) ? '/' . $view : ""; |
| 177 | 179 | |
| 178 | - if (empty($uri)) |
|
| 179 | - $uri = "/"; |
|
| 180 | + if (empty($uri)) { |
|
| 181 | + $uri = "/"; |
|
| 182 | + } |
|
| 180 | 183 | |
| 181 | 184 | $request->setUri($uri); |
| 182 | 185 | |
@@ -191,9 +194,9 @@ discard block |
||
| 191 | 194 | $view = $params["action"]; |
| 192 | 195 | |
| 193 | 196 | $this->router->setIdentifiers($module, $controller, $view); |
| 197 | + } else { |
|
| 198 | + $this->router->setIdentifiers($module, $controller, $view); |
|
| 194 | 199 | } |
| 195 | - else |
|
| 196 | - $this->router->setIdentifiers($module, $controller, $view); |
|
| 197 | 200 | |
| 198 | 201 | $this->router->run(); |
| 199 | 202 | } |
@@ -216,8 +216,9 @@ discard block |
||
| 216 | 216 | */ |
| 217 | 217 | public function getArrayResult() |
| 218 | 218 | { |
| 219 | - if (!empty($this->arrayResult)) |
|
| 220 | - return $this->arrayResult; |
|
| 219 | + if (!empty($this->arrayResult)) { |
|
| 220 | + return $this->arrayResult; |
|
| 221 | + } |
|
| 221 | 222 | |
| 222 | 223 | return $this->toArray(); |
| 223 | 224 | } |
@@ -313,8 +314,9 @@ discard block |
||
| 313 | 314 | */ |
| 314 | 315 | public function autocommit($value) |
| 315 | 316 | { |
| 316 | - if ($this->transac_mode) |
|
| 317 | - throw new \LogicException("You cannot change autocommit behavior during a transaction"); |
|
| 317 | + if ($this->transac_mode) { |
|
| 318 | + throw new \LogicException("You cannot change autocommit behavior during a transaction"); |
|
| 319 | + } |
|
| 318 | 320 | |
| 319 | 321 | $this->autocommit = $value; |
| 320 | 322 | } |
@@ -330,8 +332,9 @@ discard block |
||
| 330 | 332 | { |
| 331 | 333 | foreach ($options as $option => $value) |
| 332 | 334 | { |
| 333 | - if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) |
|
| 334 | - $this->{'set'.$option}($value); |
|
| 335 | + if (property_exists(__CLASS__, strtolower($option)) && method_exists($this, 'set'.$option)) { |
|
| 336 | + $this->{'set'.$option}($value); |
|
| 337 | + } |
|
| 335 | 338 | } |
| 336 | 339 | } |
| 337 | 340 | |
@@ -375,8 +378,9 @@ discard block |
||
| 375 | 378 | */ |
| 376 | 379 | public function reconnect() |
| 377 | 380 | { |
| 378 | - if (!$this->isConnected()) |
|
| 379 | - throw new \LogicException("Connection was not established"); |
|
| 381 | + if (!$this->isConnected()) { |
|
| 382 | + throw new \LogicException("Connection was not established"); |
|
| 383 | + } |
|
| 380 | 384 | |
| 381 | 385 | $this->disconnect(); |
| 382 | 386 | return $this->connect(); |
@@ -405,8 +409,9 @@ discard block |
||
| 405 | 409 | */ |
| 406 | 410 | public function disconnect() |
| 407 | 411 | { |
| 408 | - if (!$this->isConnected()) |
|
| 409 | - throw new \LogicException("Connection was not established"); |
|
| 412 | + if (!$this->isConnected()) { |
|
| 413 | + throw new \LogicException("Connection was not established"); |
|
| 414 | + } |
|
| 410 | 415 | } |
| 411 | 416 | |
| 412 | 417 | /** |
@@ -418,11 +423,13 @@ discard block |
||
| 418 | 423 | */ |
| 419 | 424 | public function beginTransaction() |
| 420 | 425 | { |
| 421 | - if (!$this->isConnected()) |
|
| 422 | - $this->connect(); |
|
| 426 | + if (!$this->isConnected()) { |
|
| 427 | + $this->connect(); |
|
| 428 | + } |
|
| 423 | 429 | |
| 424 | - if ($this->transac_mode) |
|
| 425 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 430 | + if ($this->transac_mode) { |
|
| 431 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_STARTED]); |
|
| 432 | + } |
|
| 426 | 433 | |
| 427 | 434 | $this->transac_mode = true; |
| 428 | 435 | } |
@@ -436,16 +443,19 @@ discard block |
||
| 436 | 443 | */ |
| 437 | 444 | public function endTransaction() |
| 438 | 445 | { |
| 439 | - if (!$this->transac_mode) |
|
| 440 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 446 | + if (!$this->transac_mode) { |
|
| 447 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_NOT_STARTED]); |
|
| 448 | + } |
|
| 441 | 449 | |
| 442 | - if (is_null($this->transac_result)) |
|
| 443 | - throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 450 | + if (is_null($this->transac_result)) { |
|
| 451 | + throw new \LogicException($this->standardErrors[Errno::DB_TRANSACTION_EMPTY]); |
|
| 452 | + } |
|
| 444 | 453 | |
| 445 | - if ($this->transac_result) |
|
| 446 | - $this->commit(); |
|
| 447 | - else |
|
| 448 | - $this->rollback(); |
|
| 454 | + if ($this->transac_result) { |
|
| 455 | + $this->commit(); |
|
| 456 | + } else { |
|
| 457 | + $this->rollback(); |
|
| 458 | + } |
|
| 449 | 459 | |
| 450 | 460 | $this->result = $this->transac_result; |
| 451 | 461 | |
@@ -141,13 +141,11 @@ |
||
| 141 | 141 | try |
| 142 | 142 | { |
| 143 | 143 | $shell->cp('foo2', 'foo3'); |
| 144 | - } |
|
| 145 | - catch (\Exception $e) |
|
| 144 | + } catch (\Exception $e) |
|
| 146 | 145 | { |
| 147 | 146 | # omitting directory |
| 148 | 147 | $errorObject = ($e instanceof \RuntimeException); |
| 149 | - } |
|
| 150 | - finally |
|
| 148 | + } finally |
|
| 151 | 149 | { |
| 152 | 150 | $this->assertTrue($errorObject, $e->getMessage()); |
| 153 | 151 | } |
@@ -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"] = "utf8"; |
|
| 34 | + if (!array_key_exists("dbchar", $options)) { |
|
| 35 | + $options["dbchar"] = "utf8"; |
|
| 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,13 +54,15 @@ discard block |
||
| 52 | 54 | */ |
| 53 | 55 | public function connect() |
| 54 | 56 | { |
| 55 | - if (!extension_loaded('mysqli')) |
|
| 56 | - throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 57 | + if (!extension_loaded('mysqli')) { |
|
| 58 | + throw new \RuntimeException("The Mysqli extension is not loaded"); |
|
| 59 | + } |
|
| 57 | 60 | |
| 58 | - if (!is_null($this->dbport) && !empty($this->dbport)) |
|
| 59 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 60 | - else |
|
| 61 | - $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 61 | + if (!is_null($this->dbport) && !empty($this->dbport)) { |
|
| 62 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname, $this->dbport); |
|
| 63 | + } else { |
|
| 64 | + $conn = @new \mysqli($this->dbhost, $this->dbuser, $this->dbpass, $this->dbname); |
|
| 65 | + } |
|
| 62 | 66 | |
| 63 | 67 | if ($conn->connect_errno) |
| 64 | 68 | { |
@@ -68,8 +72,7 @@ discard block |
||
| 68 | 72 | * the warning message "Property access is not allowed yet". |
| 69 | 73 | */ |
| 70 | 74 | throw new Exception\ConnectionException(mysqli_connect_error(), mysqli_connect_errno()); |
| 71 | - } |
|
| 72 | - else |
|
| 75 | + } else |
|
| 73 | 76 | { |
| 74 | 77 | $this->dbconn = $conn; |
| 75 | 78 | $this->dbconn->set_charset($this->dbchar); |
@@ -116,13 +119,15 @@ discard block |
||
| 116 | 119 | |
| 117 | 120 | for ($i = 0; $i < $n_params; $i++) |
| 118 | 121 | { |
| 119 | - if (is_string($param_values[$i])) |
|
| 120 | - $bind_types .= 's'; |
|
| 121 | - else if(is_float($param_values[$i])) |
|
| 122 | - $bind_types .= 'd'; |
|
| 122 | + if (is_string($param_values[$i])) { |
|
| 123 | + $bind_types .= 's'; |
|
| 124 | + } else if(is_float($param_values[$i])) { |
|
| 125 | + $bind_types .= 'd'; |
|
| 126 | + } |
|
| 123 | 127 | # [POSSIBLE BUG] - To Future revision (What about non-string and non-decimal types ?) |
| 124 | - else |
|
| 125 | - $bind_types .= 's'; |
|
| 128 | + else { |
|
| 129 | + $bind_types .= 's'; |
|
| 130 | + } |
|
| 126 | 131 | |
| 127 | 132 | $bind_values[] = '$param_values[' . $i . ']'; |
| 128 | 133 | } |
@@ -143,12 +148,12 @@ discard block |
||
| 143 | 148 | * It is useful to prevent rollback transactions on insert statements because |
| 144 | 149 | * insert statement do not free results. |
| 145 | 150 | */ |
| 146 | - if ($res) |
|
| 147 | - $this->result = $res; |
|
| 151 | + if ($res) { |
|
| 152 | + $this->result = $res; |
|
| 153 | + } |
|
| 148 | 154 | } |
| 149 | 155 | } |
| 150 | - } |
|
| 151 | - else |
|
| 156 | + } else |
|
| 152 | 157 | { |
| 153 | 158 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
| 154 | 159 | |
@@ -165,20 +170,23 @@ discard block |
||
| 165 | 170 | } |
| 166 | 171 | |
| 167 | 172 | # identify SELECT, SHOW, DESCRIBE or EXPLAIN queries |
| 168 | - if (is_object($this->result) && property_exists($this->result, 'num_rows')) |
|
| 169 | - $this->numRows = $this->result->num_rows; |
|
| 170 | - else |
|
| 173 | + if (is_object($this->result) && property_exists($this->result, 'num_rows')) { |
|
| 174 | + $this->numRows = $this->result->num_rows; |
|
| 175 | + } else |
|
| 171 | 176 | { |
| 172 | 177 | # affected_rows return the same of num_rows on select statements! |
| 173 | - if (property_exists($this->dbconn, 'affected_rows')) |
|
| 174 | - $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 178 | + if (property_exists($this->dbconn, 'affected_rows')) { |
|
| 179 | + $this->rowsAffected = $this->dbconn->affected_rows; |
|
| 180 | + } |
|
| 175 | 181 | } |
| 176 | 182 | |
| 177 | - if (property_exists($this->dbconn, 'field_count')) |
|
| 178 | - $this->numFields = $this->dbconn->field_count; |
|
| 183 | + if (property_exists($this->dbconn, 'field_count')) { |
|
| 184 | + $this->numFields = $this->dbconn->field_count; |
|
| 185 | + } |
|
| 179 | 186 | |
| 180 | - if ($this->transac_mode) |
|
| 181 | - $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 187 | + if ($this->transac_mode) { |
|
| 188 | + $this->transac_result = is_null($this->transac_result) ? $this->result: $this->transac_result && $this->result; |
|
| 189 | + } |
|
| 182 | 190 | |
| 183 | 191 | /* |
| 184 | 192 | * Because mysqli_query() returns FALSE on failure, a mysqli_result object for SELECT, SHOW, DESCRIBE or EXPLAIN queries, |
@@ -247,9 +255,8 @@ discard block |
||
| 247 | 255 | { |
| 248 | 256 | $data[] = $row; |
| 249 | 257 | } |
| 250 | - } |
|
| 251 | - else |
|
| 252 | - /* |
|
| 258 | + } else { |
|
| 259 | + /* |
|
| 253 | 260 | * "This kind of exception should lead directly to a fix in your code" |
| 254 | 261 | * So much production tests tell us this error is throwed because developers |
| 255 | 262 | * execute toArray() before execute(). |
@@ -257,6 +264,7 @@ discard block |
||
| 257 | 264 | * Ref: http://php.net/manual/en/class.logicexception.php |
| 258 | 265 | */ |
| 259 | 266 | throw new \LogicException('There are not data in the buffer!'); |
| 267 | + } |
|
| 260 | 268 | |
| 261 | 269 | $this->arrayResult = $data; |
| 262 | 270 | |
@@ -271,7 +279,8 @@ discard block |
||
| 271 | 279 | public function __destruct() |
| 272 | 280 | { |
| 273 | 281 | # prevent "Property access is not allowed yet" with @ on failure connections |
| 274 | - if ($this->dbconn !== false && !is_null($this->dbconn)) |
|
| 275 | - @$this->dbconn->close(); |
|
| 282 | + if ($this->dbconn !== false && !is_null($this->dbconn)) { |
|
| 283 | + @$this->dbconn->close(); |
|
| 284 | + } |
|
| 276 | 285 | } |
| 277 | 286 | } |
| 278 | 287 | \ No newline at end of file |
@@ -84,8 +84,9 @@ discard block |
||
| 84 | 84 | { |
| 85 | 85 | foreach ($this->ls($directory) as $item) |
| 86 | 86 | { |
| 87 | - if ($item != '.' && $item != '..') |
|
| 88 | - $contents[] = $item; |
|
| 87 | + if ($item != '.' && $item != '..') { |
|
| 88 | + $contents[] = $item; |
|
| 89 | + } |
|
| 89 | 90 | } |
| 90 | 91 | |
| 91 | 92 | if (count($contents) > 0) |
@@ -98,8 +99,7 @@ discard block |
||
| 98 | 99 | |
| 99 | 100 | $this->buffer = $directory.'/'.$i; |
| 100 | 101 | call_user_func($fileCallback, $this); |
| 101 | - } |
|
| 102 | - else if (is_dir($directory.'/'.$i)) |
|
| 102 | + } else if (is_dir($directory.'/'.$i)) |
|
| 103 | 103 | { |
| 104 | 104 | $directory_name = basename($directory).'/'.$i; |
| 105 | 105 | |
@@ -118,14 +118,15 @@ discard block |
||
| 118 | 118 | } |
| 119 | 119 | } |
| 120 | 120 | } |
| 121 | + } else if (is_file($directory)) { |
|
| 122 | + throw new \InvalidArgumentException("'$directory' is actually a file"); |
|
| 123 | + } else { |
|
| 124 | + throw new \InvalidArgumentException("The directory '$directory' does not exists"); |
|
| 121 | 125 | } |
| 122 | - else if (is_file($directory)) |
|
| 123 | - throw new \InvalidArgumentException("'$directory' is actually a file"); |
|
| 124 | - else |
|
| 125 | - throw new \InvalidArgumentException("The directory '$directory' does not exists"); |
|
| 126 | 126 | |
| 127 | - if (!is_null($callback)) |
|
| 128 | - call_user_func($callback, $this); |
|
| 127 | + if (!is_null($callback)) { |
|
| 128 | + call_user_func($callback, $this); |
|
| 129 | + } |
|
| 129 | 130 | |
| 130 | 131 | return $allContents; |
| 131 | 132 | } |
@@ -137,10 +138,11 @@ discard block |
||
| 137 | 138 | */ |
| 138 | 139 | public function pwd() |
| 139 | 140 | { |
| 140 | - if (getcwd()) |
|
| 141 | - $this->buffer = getcwd(); |
|
| 142 | - else |
|
| 143 | - return false; |
|
| 141 | + if (getcwd()) { |
|
| 142 | + $this->buffer = getcwd(); |
|
| 143 | + } else { |
|
| 144 | + return false; |
|
| 145 | + } |
|
| 144 | 146 | |
| 145 | 147 | return $this->buffer; |
| 146 | 148 | } |
@@ -159,36 +161,38 @@ discard block |
||
| 159 | 161 | |
| 160 | 162 | $path = (is_null($path) || empty($path)) ? '.' : $path; |
| 161 | 163 | |
| 162 | - if (is_file($path)) |
|
| 163 | - $filesToReturn = array($path); |
|
| 164 | - else if (is_dir($path)) |
|
| 164 | + if (is_file($path)) { |
|
| 165 | + $filesToReturn = array($path); |
|
| 166 | + } else if (is_dir($path)) |
|
| 165 | 167 | { |
| 166 | 168 | $pathIns = dir($path); |
| 167 | 169 | |
| 168 | - if ($recursive) |
|
| 169 | - $filesToReturn = $this->getContents($path); |
|
| 170 | - else |
|
| 170 | + if ($recursive) { |
|
| 171 | + $filesToReturn = $this->getContents($path); |
|
| 172 | + } else |
|
| 171 | 173 | { |
| 172 | 174 | while (($item = $pathIns->read()) !== false) |
| 173 | 175 | { |
| 174 | - if ($item != '.' && $item != '..') |
|
| 175 | - $filesToReturn[] = $item; |
|
| 176 | + if ($item != '.' && $item != '..') { |
|
| 177 | + $filesToReturn[] = $item; |
|
| 178 | + } |
|
| 176 | 179 | } |
| 177 | 180 | |
| 178 | 181 | $pathIns->close(); |
| 179 | 182 | } |
| 180 | - } |
|
| 181 | - else { |
|
| 183 | + } else { |
|
| 182 | 184 | |
| 183 | 185 | $contents = $this->ls(); |
| 184 | 186 | |
| 185 | 187 | foreach ($contents as $item) |
| 186 | 188 | { |
| 187 | - if (!empty($path)) |
|
| 188 | - if (!strlen(stristr($item, $path)) > 0) |
|
| 189 | + if (!empty($path)) { |
|
| 190 | + if (!strlen(stristr($item, $path)) > 0) |
|
| 189 | 191 | continue; |
| 190 | - if (strstr($item,'~') === false && $item != '.' && $item != '..') |
|
| 191 | - $filesToReturn[] = $item; |
|
| 192 | + } |
|
| 193 | + if (strstr($item,'~') === false && $item != '.' && $item != '..') { |
|
| 194 | + $filesToReturn[] = $item; |
|
| 195 | + } |
|
| 192 | 196 | } |
| 193 | 197 | } |
| 194 | 198 | |
@@ -208,8 +212,9 @@ discard block |
||
| 208 | 212 | |
| 209 | 213 | if (is_dir($path)) |
| 210 | 214 | { |
| 211 | - if (chdir($path)) |
|
| 212 | - return true; |
|
| 215 | + if (chdir($path)) { |
|
| 216 | + return true; |
|
| 217 | + } |
|
| 213 | 218 | } |
| 214 | 219 | |
| 215 | 220 | return false; |
@@ -249,12 +254,13 @@ discard block |
||
| 249 | 254 | */ |
| 250 | 255 | public function rm($file, $recursive = false) |
| 251 | 256 | { |
| 252 | - if (is_null($file)) |
|
| 253 | - throw new \InvalidArgumentException("Missing first parameter"); |
|
| 257 | + if (is_null($file)) { |
|
| 258 | + throw new \InvalidArgumentException("Missing first parameter"); |
|
| 259 | + } |
|
| 254 | 260 | |
| 255 | - if (file_exists($file) && !$recursive) |
|
| 256 | - unlink($file); |
|
| 257 | - elseif (is_dir($file) && $recursive) |
|
| 261 | + if (file_exists($file) && !$recursive) { |
|
| 262 | + unlink($file); |
|
| 263 | + } elseif (is_dir($file) && $recursive) |
|
| 258 | 264 | { |
| 259 | 265 | $that = $this; |
| 260 | 266 | |
@@ -291,11 +297,13 @@ discard block |
||
| 291 | 297 | */ |
| 292 | 298 | public function cp($file, $dest, $recursive = false) |
| 293 | 299 | { |
| 294 | - if (empty($file) || empty($dest)) |
|
| 295 | - throw new \InvalidArgumentException("Missing parameters"); |
|
| 300 | + if (empty($file) || empty($dest)) { |
|
| 301 | + throw new \InvalidArgumentException("Missing parameters"); |
|
| 302 | + } |
|
| 296 | 303 | |
| 297 | - if (is_dir($file) && !$recursive) |
|
| 298 | - throw new \RuntimeException("Ommiting directory <<$foo>>"); |
|
| 304 | + if (is_dir($file) && !$recursive) { |
|
| 305 | + throw new \RuntimeException("Ommiting directory <<$foo>>"); |
|
| 306 | + } |
|
| 299 | 307 | |
| 300 | 308 | $dest_exists = file_exists($dest); |
| 301 | 309 | |
@@ -308,8 +316,9 @@ discard block |
||
| 308 | 316 | |
| 309 | 317 | $files["folders"][] = is_dir($dest) ? basename($file) : $dest; |
| 310 | 318 | |
| 311 | - if (!$dest_exists) |
|
| 312 | - mkdir($dest); |
|
| 319 | + if (!$dest_exists) { |
|
| 320 | + mkdir($dest); |
|
| 321 | + } |
|
| 313 | 322 | |
| 314 | 323 | $that = $this; |
| 315 | 324 | |
@@ -331,20 +340,21 @@ discard block |
||
| 331 | 340 | { |
| 332 | 341 | foreach ($files["folders"] as $folder) |
| 333 | 342 | { |
| 334 | - if (!file_exists($dest.'/'.$folder)) |
|
| 335 | - mkdir("$dest/$folder", 0777, true); |
|
| 343 | + if (!file_exists($dest.'/'.$folder)) { |
|
| 344 | + mkdir("$dest/$folder", 0777, true); |
|
| 345 | + } |
|
| 336 | 346 | } |
| 337 | 347 | |
| 338 | 348 | if (count($files["files"])) |
| 339 | 349 | { |
| 340 | 350 | foreach ($files["files"] as $item) |
| 341 | 351 | { |
| 342 | - if (!file_exists("$dest/$item")) |
|
| 343 | - copy($item, $dest.'/'.$item); |
|
| 352 | + if (!file_exists("$dest/$item")) { |
|
| 353 | + copy($item, $dest.'/'.$item); |
|
| 354 | + } |
|
| 344 | 355 | } |
| 345 | 356 | } |
| 346 | - } |
|
| 347 | - else |
|
| 357 | + } else |
|
| 348 | 358 | { |
| 349 | 359 | # directory previoulsy created |
| 350 | 360 | array_shift($files["folders"]); |
@@ -358,8 +368,9 @@ discard block |
||
| 358 | 368 | { |
| 359 | 369 | $_folder = preg_replace($from, "", $folder, 1); |
| 360 | 370 | |
| 361 | - if (!file_exists($dest.'/'.$_folder)) |
|
| 362 | - mkdir("$dest/$_folder", 0777, true); |
|
| 371 | + if (!file_exists($dest.'/'.$_folder)) { |
|
| 372 | + mkdir("$dest/$_folder", 0777, true); |
|
| 373 | + } |
|
| 363 | 374 | } |
| 364 | 375 | } |
| 365 | 376 | |
@@ -369,8 +380,9 @@ discard block |
||
| 369 | 380 | { |
| 370 | 381 | $_item = preg_replace($from, "", $item, 1); |
| 371 | 382 | |
| 372 | - if (!file_exists("$dest/$_item")) |
|
| 373 | - copy($item, $dest.'/'.$_item); |
|
| 383 | + if (!file_exists("$dest/$_item")) { |
|
| 384 | + copy($item, $dest.'/'.$_item); |
|
| 385 | + } |
|
| 374 | 386 | } |
| 375 | 387 | } |
| 376 | 388 | } |
@@ -378,11 +390,11 @@ discard block |
||
| 378 | 390 | ); |
| 379 | 391 | |
| 380 | 392 | |
| 393 | + } else if (is_dir($dest)) { |
|
| 394 | + copy($file, $dest.'/'.$file); |
|
| 395 | + } else { |
|
| 396 | + copy($file, $dest); |
|
| 381 | 397 | } |
| 382 | - else if (is_dir($dest)) |
|
| 383 | - copy($file, $dest.'/'.$file); |
|
| 384 | - else |
|
| 385 | - copy($file, $dest); |
|
| 386 | 398 | |
| 387 | 399 | return true; |
| 388 | 400 | } |
@@ -397,17 +409,21 @@ discard block |
||
| 397 | 409 | */ |
| 398 | 410 | public function mv($oldfile, $newfile) |
| 399 | 411 | { |
| 400 | - if (empty($oldfile) || empty($newfile)) |
|
| 401 | - throw new \InvalidArgumentException("Missing parameters"); |
|
| 412 | + if (empty($oldfile) || empty($newfile)) { |
|
| 413 | + throw new \InvalidArgumentException("Missing parameters"); |
|
| 414 | + } |
|
| 402 | 415 | |
| 403 | - if (is_dir($newfile)) |
|
| 404 | - $newfile .= '/'.basename($oldfile); |
|
| 416 | + if (is_dir($newfile)) { |
|
| 417 | + $newfile .= '/'.basename($oldfile); |
|
| 418 | + } |
|
| 405 | 419 | |
| 406 | - if ($oldfile == $newfile) |
|
| 407 | - throw new \Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 420 | + if ($oldfile == $newfile) { |
|
| 421 | + throw new \Exception("'$oldfile' and '$newfile' are the same file"); |
|
| 422 | + } |
|
| 408 | 423 | |
| 409 | - if(!rename($oldfile, $newfile)) |
|
| 410 | - return false; |
|
| 424 | + if(!rename($oldfile, $newfile)) { |
|
| 425 | + return false; |
|
| 426 | + } |
|
| 411 | 427 | |
| 412 | 428 | return true; |
| 413 | 429 | } |
@@ -423,21 +439,24 @@ discard block |
||
| 423 | 439 | */ |
| 424 | 440 | public function mkdir($dir, $dest = null, $recursive = null) |
| 425 | 441 | { |
| 426 | - if (empty($dir)) |
|
| 427 | - throw new \InvalidArgumentException("Missing first parameter"); |
|
| 442 | + if (empty($dir)) { |
|
| 443 | + throw new \InvalidArgumentException("Missing first parameter"); |
|
| 444 | + } |
|
| 428 | 445 | |
| 429 | - if (empty($dest)) |
|
| 430 | - $dest = '.'; |
|
| 446 | + if (empty($dest)) { |
|
| 447 | + $dest = '.'; |
|
| 448 | + } |
|
| 431 | 449 | |
| 432 | 450 | $recursive = (is_null($recursive)) ? false : $recursive; |
| 433 | 451 | |
| 434 | - if ($recursive) |
|
| 435 | - mkdir("$dest/$dir", 0777, true); |
|
| 436 | - else { |
|
| 452 | + if ($recursive) { |
|
| 453 | + mkdir("$dest/$dir", 0777, true); |
|
| 454 | + } else { |
|
| 437 | 455 | if (!is_dir($dir)) |
| 438 | 456 | { |
| 439 | - if(!mkdir("$dir", 0777)) |
|
| 440 | - return false; |
|
| 457 | + if(!mkdir("$dir", 0777)) { |
|
| 458 | + return false; |
|
| 459 | + } |
|
| 441 | 460 | } |
| 442 | 461 | } |
| 443 | 462 | return true; |
@@ -452,12 +471,14 @@ discard block |
||
| 452 | 471 | */ |
| 453 | 472 | public function rmdir($dir) |
| 454 | 473 | { |
| 455 | - if (is_null($dir) || empty($dir)) |
|
| 456 | - throw new \RuntimeException("Missing first parameter"); |
|
| 474 | + if (is_null($dir) || empty($dir)) { |
|
| 475 | + throw new \RuntimeException("Missing first parameter"); |
|
| 476 | + } |
|
| 457 | 477 | |
| 458 | - if (rmdir($dir)) |
|
| 459 | - return true; |
|
| 460 | - else |
|
| 461 | - return false; |
|
| 478 | + if (rmdir($dir)) { |
|
| 479 | + return true; |
|
| 480 | + } else { |
|
| 481 | + return false; |
|
| 482 | + } |
|
| 462 | 483 | } |
| 463 | 484 | } |
| 464 | 485 | \ No newline at end of file |
@@ -76,11 +76,13 @@ discard block |
||
| 76 | 76 | $event = $eventHandlers; |
| 77 | 77 | $clousure = function(){}; |
| 78 | 78 | |
| 79 | - if (!array_key_exists('success', $event)) |
|
| 80 | - $event["success"] = $clousure; |
|
| 79 | + if (!array_key_exists('success', $event)) { |
|
| 80 | + $event["success"] = $clousure; |
|
| 81 | + } |
|
| 81 | 82 | |
| 82 | - if (!array_key_exists('error', $event)) |
|
| 83 | - $event["error"] = $clousure; |
|
| 83 | + if (!array_key_exists('error', $event)) { |
|
| 84 | + $event["error"] = $clousure; |
|
| 85 | + } |
|
| 84 | 86 | |
| 85 | 87 | $listener = false; |
| 86 | 88 | |
@@ -90,8 +92,7 @@ discard block |
||
| 90 | 92 | $this->error($errno, socket_strerror($errno)); |
| 91 | 93 | |
| 92 | 94 | throw new \RuntimeException("Could not set socket to listen"); |
| 93 | - } |
|
| 94 | - else { |
|
| 95 | + } else { |
|
| 95 | 96 | |
| 96 | 97 | echo "\n"; |
| 97 | 98 | echo "Server Started : " . date('Y-m-d H:i:s') . "\n"; |
@@ -114,8 +115,9 @@ discard block |
||
| 114 | 115 | socket_close($spawn); |
| 115 | 116 | } |
| 116 | 117 | |
| 117 | - if (!$listener) |
|
| 118 | - call_user_func($event["error"], $this->getLastError()); |
|
| 118 | + if (!$listener) { |
|
| 119 | + call_user_func($event["error"], $this->getLastError()); |
|
| 120 | + } |
|
| 119 | 121 | |
| 120 | 122 | return $listener; |
| 121 | 123 | } |
@@ -84,12 +84,10 @@ discard block |
||
| 84 | 84 | |
| 85 | 85 | try { |
| 86 | 86 | $conn->disconnect(); |
| 87 | - } |
|
| 88 | - catch (\Exception $e) |
|
| 87 | + } catch (\Exception $e) |
|
| 89 | 88 | { |
| 90 | 89 | $errorObject = ($e instanceof \LogicException); |
| 91 | - } |
|
| 92 | - finally |
|
| 90 | + } finally |
|
| 93 | 91 | { |
| 94 | 92 | $this->assertNotTrue($conn->isConnected()); |
| 95 | 93 | $this->assertTrue($errorObject, $e->getMessage()); |
@@ -125,12 +123,10 @@ discard block |
||
| 125 | 123 | |
| 126 | 124 | try { |
| 127 | 125 | $conn->reconnect(); |
| 128 | - } |
|
| 129 | - catch (\Exception $e) |
|
| 126 | + } catch (\Exception $e) |
|
| 130 | 127 | { |
| 131 | 128 | $errorObject = ($e instanceof \LogicException); |
| 132 | - } |
|
| 133 | - finally |
|
| 129 | + } finally |
|
| 134 | 130 | { |
| 135 | 131 | $this->assertTrue($errorObject, $e->getMessage()); |
| 136 | 132 | $this->assertNotTrue($conn->isConnected()); |
@@ -156,13 +152,11 @@ discard block |
||
| 156 | 152 | try |
| 157 | 153 | { |
| 158 | 154 | $conn->connect(); |
| 159 | - } |
|
| 160 | - catch (\Exception $e) |
|
| 155 | + } catch (\Exception $e) |
|
| 161 | 156 | { |
| 162 | 157 | $errorObject = ($e instanceof ConnectionException); |
| 163 | 158 | $message = $e->getMessage(); |
| 164 | - } |
|
| 165 | - finally |
|
| 159 | + } finally |
|
| 166 | 160 | { |
| 167 | 161 | $this->assertTrue($errorObject, $message); |
| 168 | 162 | $this->assertNotTrue($conn->isConnected()); |
@@ -242,13 +236,11 @@ discard block |
||
| 242 | 236 | { |
| 243 | 237 | $sql = "INSERT INTO MYTABLE (DESCRIPTION, WRONG) VALUES ('Hello world!')"; |
| 244 | 238 | $conn->execute($sql); |
| 245 | - } |
|
| 246 | - catch (\Exception $e) |
|
| 239 | + } catch (\Exception $e) |
|
| 247 | 240 | { |
| 248 | 241 | $errorObject = ($e instanceof InvalidQueryException); |
| 249 | 242 | $message = $e->getMessage(); |
| 250 | - } |
|
| 251 | - finally |
|
| 243 | + } finally |
|
| 252 | 244 | { |
| 253 | 245 | $this->assertTrue($errorObject, $message); |
| 254 | 246 | } |
@@ -517,8 +509,7 @@ discard block |
||
| 517 | 509 | |
| 518 | 510 | $sql = "INSERT INTO MYTABLE (DESCRIPTION, WRONG) VALUES ('TRANS_SHORTCUT_2')"; |
| 519 | 511 | $conn->execute($sql); |
| 520 | - } |
|
| 521 | - catch (InvalidQueryException $e) |
|
| 512 | + } catch (InvalidQueryException $e) |
|
| 522 | 513 | { |
| 523 | 514 | $message = $e->getMessage(); |
| 524 | 515 | #·not necessary! |
@@ -162,8 +162,9 @@ discard block |
||
| 162 | 162 | { |
| 163 | 163 | $config = $module->getConfig(); |
| 164 | 164 | |
| 165 | - if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) |
|
| 166 | - throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists"); |
|
| 165 | + if (!array_key_exists($view, $config["view_manager"]["view_map"]) || !file_exists($config["view_manager"]["view_map"][$view])) { |
|
| 166 | + throw new Exception\ViewNotFoundException("The 'view' template " . $view . " does not exists"); |
|
| 167 | + } |
|
| 167 | 168 | |
| 168 | 169 | $this->view = $config["view_manager"]["view_map"][$view]; |
| 169 | 170 | } |
@@ -193,8 +194,9 @@ discard block |
||
| 193 | 194 | { |
| 194 | 195 | foreach ($params as $param => $value) |
| 195 | 196 | { |
| 196 | - if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param)) |
|
| 197 | - $this->{'set'.$param}($value); |
|
| 197 | + if (property_exists(__CLASS__, strtolower($param)) && method_exists($this, 'set'.$param)) { |
|
| 198 | + $this->{'set'.$param}($value); |
|
| 199 | + } |
|
| 198 | 200 | } |
| 199 | 201 | } |
| 200 | 202 | |
@@ -223,25 +225,28 @@ discard block |
||
| 223 | 225 | |
| 224 | 226 | if ($controller->getTerminal()) |
| 225 | 227 | { |
| 226 | - if (file_exists($view)) |
|
| 227 | - include $view; |
|
| 228 | - } |
|
| 229 | - else |
|
| 228 | + if (file_exists($view)) { |
|
| 229 | + include $view; |
|
| 230 | + } |
|
| 231 | + } else |
|
| 230 | 232 | { |
| 231 | - if (!is_null($this->view) && !file_exists($this->view)) |
|
| 232 | - throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 233 | + if (!is_null($this->view) && !file_exists($this->view)) { |
|
| 234 | + throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 235 | + } |
|
| 233 | 236 | |
| 234 | 237 | $config = $controller->getModule()->getConfig(); |
| 235 | 238 | |
| 236 | 239 | $layout = $controller->getLayout(); |
| 237 | 240 | |
| 238 | - if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) |
|
| 239 | - throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php"); |
|
| 241 | + if (!array_key_exists($controller->getLayout(), $config["view_manager"]["template_map"])) { |
|
| 242 | + throw new Exception\PageNotFoundException("The 'template' " . $layout . " was not defined in module.config.php"); |
|
| 243 | + } |
|
| 240 | 244 | |
| 241 | 245 | $template = $config["view_manager"]["template_map"][$controller->getLayout()]; |
| 242 | 246 | |
| 243 | - if (!file_exists($template)) |
|
| 244 | - throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists"); |
|
| 247 | + if (!file_exists($template)) { |
|
| 248 | + throw new Exception\PageNotFoundException("The 'template' " . $template . " does not exists"); |
|
| 249 | + } |
|
| 245 | 250 | |
| 246 | 251 | include $template; |
| 247 | 252 | } |
@@ -268,8 +273,9 @@ discard block |
||
| 268 | 273 | */ |
| 269 | 274 | public function content() |
| 270 | 275 | { |
| 271 | - if (!file_exists($this->view)) |
|
| 272 | - throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 276 | + if (!file_exists($this->view)) { |
|
| 277 | + throw new Exception\ViewNotFoundException("The 'view' template " . $this->view . " does not exists"); |
|
| 278 | + } |
|
| 273 | 279 | |
| 274 | 280 | include $this->view; |
| 275 | 281 | } |