| Conditions | 9 |
| Paths | 42 |
| Total Lines | 60 |
| Code Lines | 36 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 3 | ||
| Bugs | 0 | Features | 1 |
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 |
||
| 54 | public function query($sql, $params = array()) |
||
| 55 | { |
||
| 56 | |||
| 57 | // Tracy Debugger |
||
| 58 | $this->log['query_total_time'] = 0; |
||
| 59 | |||
| 60 | $trace = debug_backtrace(); |
||
| 61 | $filename = (isset($trace[0]['file'])) ? $trace[0]['file'] : '---'; |
||
| 62 | $cmsPath = str_replace('upload/engine/', '', $_SERVER['DOCUMENT_ROOT'] . '/engine/'); |
||
| 63 | $cmsPath = str_replace('public/engine/', '', $cmsPath); |
||
| 64 | $pureFile = str_replace($cmsPath, '', $filename); |
||
| 65 | |||
| 66 | $bench = new \Ubench; |
||
| 67 | $bench->start(); |
||
| 68 | // |
||
| 69 | |||
| 70 | $this->statement = $this->connection->prepare($sql); |
||
| 71 | |||
| 72 | $result = false; |
||
| 73 | |||
| 74 | try { |
||
| 75 | if ($this->statement && $this->statement->execute($params)) { |
||
| 76 | $data = array(); |
||
| 77 | |||
| 78 | while ($row = $this->statement->fetch(\PDO::FETCH_ASSOC)) { |
||
| 79 | $data[] = $row; |
||
| 80 | } |
||
| 81 | |||
| 82 | $result = new \stdClass(); |
||
| 83 | $result->row = isset($data[0]) ? $data[0] : array(); |
||
| 84 | $result->rows = $data; |
||
| 85 | $result->num_rows = $this->statement->rowCount(); |
||
| 86 | } |
||
| 87 | } catch (\PDOException $e) { |
||
| 88 | throw new \Exception('Error: ' . $e->getMessage() . ' Error Code : ' . $e->getCode() . ' <br />' . $sql); |
||
| 89 | } |
||
| 90 | |||
| 91 | // Tracy Debugger |
||
| 92 | $bench->end(); |
||
| 93 | $exec_time = $bench->getTime(); |
||
| 94 | |||
| 95 | if (!isset($this->log['query_total_time'])) { |
||
| 96 | $this->log['query_total_time'] = 0; |
||
| 97 | } |
||
| 98 | |||
| 99 | $this->log['query_total_time'] = (float) $this->log['query_total_time'] + (float) $exec_time; |
||
| 100 | $this->log['file'] = $pureFile; |
||
| 101 | $this->log['time'] = $exec_time; |
||
| 102 | $this->log['query'] = \SqlFormatter::format($sql); |
||
| 103 | $_SESSION['_tracy']['sql_log'][] = $this->log; |
||
| 104 | // |
||
| 105 | |||
| 106 | if (!$result) { |
||
| 107 | $result = new \stdClass(); |
||
| 108 | $result->row = array(); |
||
| 109 | $result->rows = array(); |
||
| 110 | $result->num_rows = 0; |
||
| 111 | } |
||
| 112 | |||
| 113 | return $result; |
||
| 114 | } |
||
| 183 |