Conditions | 34 |
Paths | 36 |
Total Lines | 135 |
Code Lines | 88 |
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 |
||
127 | final public function __execute($method, $arguments, $filepath) |
||
128 | { |
||
129 | $result = null; |
||
130 | |||
131 | try { |
||
132 | if (preg_match('/^(?:select|(?:dele|upda)te|insert)$/', $method)) { |
||
133 | $sql = $arguments[0]; |
||
134 | $bind = null; |
||
135 | if (array_key_exists(1, $arguments)) { |
||
136 | $bind = $arguments[1]; |
||
137 | } |
||
138 | |||
139 | if (is_string($sql)) { |
||
140 | if ($method !== 'select' && $this->isAutoCommit) { |
||
141 | $this->manager->beginTransaction(Connection::TRANSACTION_READ_COMMITTED); |
||
142 | } |
||
143 | if (is_array($bind)) { |
||
144 | $result = $this->manager->query($sql, $bind)->{$method}(); |
||
145 | } else { |
||
146 | $result = $this->manager->query($sql)->{$method}(); |
||
147 | } |
||
148 | } else { |
||
149 | throw new DatabaseException("Invalid SQL or bind parameters: " . $sql .", " . strval($bind)); |
||
150 | } |
||
151 | } else { |
||
152 | $bind = null; |
||
153 | if (array_key_exists(0, $arguments)) { |
||
154 | $bind = $arguments[0]; |
||
155 | } |
||
156 | |||
157 | $trace = debug_backtrace(); |
||
158 | $modelMethod = null; |
||
159 | for ($i = 0; $i < count($trace); $i++) { |
||
160 | if ($this->inArray($trace[$i]["function"], ["__call", "__execute"])) { |
||
161 | continue; |
||
162 | } |
||
163 | |||
164 | if ($trace[$i]["function"] !== null) { |
||
165 | $modelMethod = $trace[$i]["function"]; |
||
166 | break; |
||
167 | } |
||
168 | } |
||
169 | |||
170 | $namespace = substr($this->getNamespace($filepath), 1); |
||
171 | $queryKey = $namespace . "\\" . basename($filepath, ".php") . "#" . $modelMethod; |
||
172 | |||
173 | $query = null; |
||
174 | foreach ($this->queryAnnotations as $queryAnnotation) { |
||
175 | $queryFunctions = $queryAnnotation->get($queryKey); |
||
176 | |||
177 | if ($queryFunctions === null) { |
||
178 | continue; |
||
179 | } |
||
180 | |||
181 | foreach ($queryFunctions as $queryFunction) { |
||
182 | $xmlObjectList = $queryFunction->fetch(); |
||
183 | foreach ($xmlObjectList as $xmlObject) { |
||
184 | if ($xmlObject !== null) { |
||
185 | $xmlElement = $xmlObject->xpath("//mapper[@namespace='$namespace']/*[@id='$method']"); |
||
186 | |||
187 | if (!empty($xmlElement)) { |
||
188 | $query = ["sql" => trim($xmlElement[0]->__toString()), "method" => $xmlElement[0]->getName()]; |
||
189 | $entity = $xmlElement[0]->attributes()["entity"]; |
||
190 | $query["entity"] = $entity !== null ? $entity->__toString() : null; |
||
191 | break; |
||
192 | } |
||
193 | } |
||
194 | } |
||
195 | } |
||
196 | } |
||
197 | |||
198 | if ($query === null) { |
||
199 | throw new DatabaseException("SQL statement can't getting from xml file: " . $modelMethod); |
||
200 | } |
||
201 | |||
202 | $sql = $query["sql"]; |
||
203 | $method = $query["method"]; |
||
204 | $entityClassPath = $query["entity"]; |
||
205 | |||
206 | if ($entityClassPath !== null) { |
||
207 | if (!class_exists($entityClassPath)) { |
||
208 | throw new DatabaseException("Entity classpath is not found: " . $entityClassPath); |
||
209 | } |
||
210 | |||
211 | switch ($method) { |
||
212 | case "select": |
||
213 | if (is_string($sql)) { |
||
214 | if (is_array($bind)) { |
||
215 | $result = $this->manager->query($sql, $bind)->select()->toEntity($entityClassPath); |
||
216 | } else { |
||
217 | $result = $this->manager->query($sql)->select()->toEntity($entityClassPath); |
||
218 | } |
||
219 | } else { |
||
220 | $errorMessage = "Invalid SQL or bind parameters: " . $sql; |
||
221 | if (is_array($bind)) { |
||
222 | $errorMessage .= ", " . strval($bind); |
||
223 | } |
||
224 | |||
225 | throw new DatabaseException($errorMessage); |
||
226 | } |
||
227 | |||
228 | break; |
||
229 | case "insert": |
||
230 | case "update": |
||
231 | case "delete": |
||
232 | // Not implement |
||
233 | throw new DatabaseException("Entity mapping is select only."); |
||
234 | } |
||
235 | } else { |
||
236 | if (is_string($sql)) { |
||
237 | if ($method !== 'select' && $this->isAutoCommit) { |
||
238 | $this->manager->beginTransaction(Connection::TRANSACTION_READ_COMMITTED); |
||
239 | } |
||
240 | if (is_array($bind)) { |
||
241 | $result = $this->manager->query($sql, $bind)->{$method}(); |
||
242 | } else { |
||
243 | $result = $this->manager->query($sql)->{$method}(); |
||
244 | } |
||
245 | } else { |
||
246 | $errorMessage = "Invalid SQL or bind parameters: " . $sql; |
||
247 | if (is_array($bind)) { |
||
248 | $errorMessage .= ", " . strval($bind); |
||
249 | } |
||
250 | |||
251 | throw new DatabaseException($errorMessage); |
||
252 | } |
||
253 | } |
||
254 | } |
||
255 | } catch (DatabaseException $e) { |
||
256 | $this->manager->rollback(); |
||
257 | $this->manager->disconnect(); |
||
258 | throw $e; |
||
259 | } |
||
260 | |||
261 | return $result; |
||
262 | } |
||
301 |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths