Conditions | 8 |
Paths | 8 |
Total Lines | 69 |
Code Lines | 38 |
Lines | 0 |
Ratio | 0 % |
Changes | 7 | ||
Bugs | 0 | Features | 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 |
||
125 | public function query($query, array $parameters = array()) |
||
126 | { |
||
127 | if (!$query instanceof Query) { |
||
128 | $query = new Query($query, $parameters); |
||
129 | } |
||
130 | |||
131 | $this->lastResult = null; |
||
132 | |||
133 | $this->connect(); |
||
134 | |||
135 | if (!$this->connected()) { |
||
136 | $this->lastResult = new Result($query, array(), array(), $this->error()); |
||
137 | |||
138 | $this->event('sqlserver.query', array($this->lastResult)); |
||
139 | |||
140 | return $this->lastResult; |
||
141 | } |
||
142 | |||
143 | $this->event('sqlserver.prequery', array($query)); |
||
144 | |||
145 | $mssql_result = sqlsrv_query($this->connection, $query->string, $query->parameters, array( |
||
146 | 'Scrollable' => SQLSRV_CURSOR_CLIENT_BUFFERED |
||
147 | )); |
||
148 | |||
149 | $result = array( |
||
150 | 'data' => array(), |
||
151 | 'fields' => array(), |
||
152 | 'affected' => null, |
||
153 | 'num_rows' => null, |
||
154 | 'insert_id' => null |
||
155 | ); |
||
156 | |||
157 | $error = $this->error(); |
||
158 | |||
159 | if ($mssql_result === false || $error) { |
||
|
|||
160 | $this->lastResult = new Result($query, array(), array(), $error); |
||
161 | |||
162 | $this->event('sqlserver.query', array($this->lastResult)); |
||
163 | |||
164 | return $this->lastResult; |
||
165 | } |
||
166 | |||
167 | $result['num_rows'] = sqlsrv_num_rows($mssql_result); |
||
168 | |||
169 | if ($result['num_rows']) { |
||
170 | while ($row = sqlsrv_fetch_array($mssql_result, SQLSRV_FETCH_ASSOC)) { |
||
171 | if (!$result['fields']) { |
||
172 | $result['fields'] = array_keys($row); |
||
173 | } |
||
174 | |||
175 | $result['data'][] = $row; |
||
176 | } |
||
177 | } |
||
178 | |||
179 | $result['insert_id'] = $this->queryInsertId($query); |
||
180 | $result['affected'] = $this->queryAffected($query); |
||
181 | |||
182 | $info = array( |
||
183 | 'count' => $result['num_rows'], |
||
184 | 'fields' => $result['fields'], |
||
185 | 'affected' => $result['affected'], |
||
186 | 'insert_id' => $result['insert_id'] |
||
187 | ); |
||
188 | |||
189 | $this->lastResult = new Result($query, $result['data'], $info, $error); |
||
190 | |||
191 | $this->event('sqlserver.query', array($this->lastResult)); |
||
192 | |||
193 | return $this->lastResult; |
||
194 | } |
||
215 |