| Conditions | 10 |
| Paths | 10 |
| Total Lines | 33 |
| Code Lines | 19 |
| 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 |
||
| 73 | protected function onNotSuccessfulTest(Throwable $e) : void |
||
| 74 | { |
||
| 75 | if ($e instanceof AssertionFailedError) { |
||
| 76 | throw $e; |
||
| 77 | } |
||
| 78 | |||
| 79 | if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { |
||
| 80 | $queries = ""; |
||
| 81 | $i = count($this->_sqlLoggerStack->queries); |
||
| 82 | foreach (array_reverse($this->_sqlLoggerStack->queries) AS $query) { |
||
| 83 | $params = array_map(function($p) { if (is_object($p)) return get_class($p); else return "'".print_r($p, true)."'"; }, $query['params'] ?: array()); |
||
|
|
|||
| 84 | $queries .= ($i+1).". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; |
||
| 85 | $i--; |
||
| 86 | } |
||
| 87 | |||
| 88 | $trace = $e->getTrace(); |
||
| 89 | $traceMsg = ""; |
||
| 90 | foreach($trace AS $part) { |
||
| 91 | if(isset($part['file'])) { |
||
| 92 | if(strpos($part['file'], "PHPUnit/") !== false) { |
||
| 93 | // Beginning with PHPUnit files we don't print the trace anymore. |
||
| 94 | break; |
||
| 95 | } |
||
| 96 | |||
| 97 | $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | |||
| 101 | $message = "[".get_class($e)."] ".$e->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; |
||
| 102 | |||
| 103 | throw new \Exception($message, (int)$e->getCode(), $e); |
||
| 104 | } |
||
| 105 | throw $e; |
||
| 106 | } |
||
| 123 |