| Conditions | 12 |
| Paths | 32 |
| Total Lines | 72 |
| Code Lines | 37 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 88 | public function execute($sql, Array $params = []) |
||
| 89 | { |
||
| 90 | $this->numRows = 0; |
||
| 91 | $this->numFields = 0; |
||
| 92 | $this->rowsAffected = 0; |
||
| 93 | |||
| 94 | $this->arrayResult = null; |
||
| 95 | |||
| 96 | $this->result = $stid = @oci_parse($this->dbconn, $sql); |
||
| 97 | |||
| 98 | if (!$stid) |
||
|
|
|||
| 99 | { |
||
| 100 | $error = $stid ? oci_error($stid) : oci_error(); |
||
| 101 | |||
| 102 | if (!empty($error)) |
||
| 103 | { |
||
| 104 | $error = [ |
||
| 105 | "message" => "Could not prepare statement!" |
||
| 106 | ]; |
||
| 107 | |||
| 108 | $this->error($error["message"]); |
||
| 109 | } |
||
| 110 | else |
||
| 111 | $this->error($error["code"], $error["message"]); |
||
| 112 | |||
| 113 | if (array_key_exists("code", $error)) |
||
| 114 | throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
||
| 115 | else |
||
| 116 | throw new Exception\InvalidQueryException($error["message"]); |
||
| 117 | } |
||
| 118 | |||
| 119 | # Bound variables |
||
| 120 | if (count($params)) |
||
| 121 | { |
||
| 122 | $param_keys = array_keys($params); |
||
| 123 | $param_values = array_values($params); |
||
| 124 | |||
| 125 | for ($i = 0; $i < count($params); $i++) |
||
| 126 | { |
||
| 127 | oci_bind_by_name($stid, $param_keys[$i], $param_values[$i], -1); |
||
| 128 | } |
||
| 129 | } |
||
| 130 | |||
| 131 | $prev_error_handler = set_error_handler(['\Drone\Error\ErrorHandler', 'errorControlOperator'], E_ALL); |
||
| 132 | |||
| 133 | // may be throw a Fatal error (Ex: Maximum execution time) |
||
| 134 | $r = ($this->transac_mode) ? oci_execute($stid, OCI_NO_AUTO_COMMIT) : oci_execute($stid, OCI_COMMIT_ON_SUCCESS); |
||
| 135 | |||
| 136 | set_error_handler($prev_error_handler); |
||
| 137 | |||
| 138 | if (!$r) |
||
| 139 | { |
||
| 140 | $error = oci_error($stid); |
||
| 141 | $this->error($error["code"], $error["message"]); |
||
| 142 | |||
| 143 | throw new Exception\InvalidQueryException($error["message"], $error["code"]); |
||
| 144 | } |
||
| 145 | |||
| 146 | # This should be before of getArrayResult() because oci_fetch() is incremental. |
||
| 147 | $this->rowsAffected = oci_num_rows($stid); |
||
| 148 | |||
| 149 | $rows = $this->getArrayResult(); |
||
| 150 | |||
| 151 | $this->numRows = count($rows); |
||
| 152 | $this->numFields = oci_num_fields($stid); |
||
| 153 | |||
| 154 | if ($this->transac_mode) |
||
| 155 | $this->transac_result = is_null($this->transac_result) ? $stid: $this->transac_result && $stid; |
||
| 156 | |||
| 157 | $this->result = $stid; |
||
| 158 | |||
| 159 | return $this->result; |
||
| 160 | } |
||
| 230 | } |