| Conditions | 11 |
| Paths | 10 |
| Total Lines | 41 |
| Code Lines | 25 |
| 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 |
||
| 60 | protected function onNotSuccessfulTest(\Throwable $t) |
||
| 61 | { |
||
| 62 | if ($t instanceof \PHPUnit\Framework\AssertionFailedError) { |
||
| 63 | throw $t; |
||
| 64 | } |
||
| 65 | |||
| 66 | if(isset($this->_sqlLoggerStack->queries) && count($this->_sqlLoggerStack->queries)) { |
||
| 67 | $queries = ""; |
||
| 68 | $i = count($this->_sqlLoggerStack->queries); |
||
| 69 | foreach (array_reverse($this->_sqlLoggerStack->queries) as $query) { |
||
| 70 | $params = array_map(function($p) { |
||
| 71 | if (is_object($p)) { |
||
| 72 | return get_class($p); |
||
| 73 | } elseif (is_scalar($p)) { |
||
| 74 | return "'".$p."'"; |
||
| 75 | } |
||
| 76 | |||
| 77 | return var_export($p, true); |
||
| 78 | }, $query['params'] ?: array()); |
||
| 79 | $queries .= $i.". SQL: '".$query['sql']."' Params: ".implode(", ", $params).PHP_EOL; |
||
| 80 | $i--; |
||
| 81 | } |
||
| 82 | |||
| 83 | $trace = $t->getTrace(); |
||
| 84 | $traceMsg = ""; |
||
| 85 | foreach($trace as $part) { |
||
| 86 | if(isset($part['file'])) { |
||
| 87 | if(strpos($part['file'], "PHPUnit/") !== false) { |
||
| 88 | // Beginning with PHPUnit files we don't print the trace anymore. |
||
| 89 | break; |
||
| 90 | } |
||
| 91 | |||
| 92 | $traceMsg .= $part['file'].":".$part['line'].PHP_EOL; |
||
| 93 | } |
||
| 94 | } |
||
| 95 | |||
| 96 | $message = "[".get_class($t)."] ".$t->getMessage().PHP_EOL.PHP_EOL."With queries:".PHP_EOL.$queries.PHP_EOL."Trace:".PHP_EOL.$traceMsg; |
||
| 97 | |||
| 98 | throw new \Exception($message, (int) $t->getCode(), $t); |
||
| 99 | } |
||
| 100 | throw $t; |
||
| 101 | } |
||
| 103 |