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