| Conditions | 10 |
| Paths | 14 |
| Total Lines | 34 |
| Code Lines | 22 |
| 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 |
||
| 42 | public function assertThrowsWithMessage(callable $callback, $throws, $message) |
||
| 43 | { |
||
| 44 | $this->parseThrows($throws, $message); |
||
| 45 | |||
| 46 | try { |
||
| 47 | call_user_func($callback); |
||
| 48 | } catch (AssertionFailedError $e) { |
||
| 49 | if ($throws !== get_class($e)) { |
||
| 50 | throw $e; |
||
| 51 | } |
||
| 52 | if ($this->exceptionMessageDoesNotMatchExpected($e, $message)) { |
||
| 53 | throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received"); |
||
| 54 | } |
||
| 55 | } catch (Exception $e) { |
||
| 56 | if ($throws) { |
||
| 57 | if ($throws !== get_class($e)) { |
||
| 58 | throw new AssertionFailedError("exception '$throws' was expected, but " . get_class($e) . ' was thrown'); |
||
| 59 | } |
||
| 60 | if ($this->exceptionMessageDoesNotMatchExpected($e, $message)) { |
||
| 61 | throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received"); |
||
| 62 | } |
||
| 63 | } else { |
||
| 64 | throw $e; |
||
| 65 | } |
||
| 66 | } |
||
| 67 | |||
| 68 | if ($throws) { |
||
| 69 | if (isset($e)) { |
||
| 70 | static::assertTrue(true, 'exception handled'); |
||
| 71 | } else { |
||
| 72 | throw new AssertionFailedError("exception '$throws' was not thrown as expected"); |
||
| 73 | } |
||
| 74 | } |
||
| 75 | } |
||
| 76 | |||
| 117 |