| Conditions | 10 |
| Paths | 14 |
| Total Lines | 37 |
| Code Lines | 23 |
| 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 |
||
| 43 | public function assertThrowsWithMessage($throws, $message, callable $fn) |
||
| 44 | { |
||
| 45 | /** @var $this TestCase * */ |
||
| 46 | $result = $this->getTestResultObject(); |
||
|
|
|||
| 47 | |||
| 48 | $this->parseThrows($throws, $message); |
||
| 49 | |||
| 50 | try { |
||
| 51 | call_user_func($fn); |
||
| 52 | } catch (AssertionFailedError $e) { |
||
| 53 | if ($throws !== get_class($e)) { |
||
| 54 | throw $e; |
||
| 55 | } |
||
| 56 | if ($this->exceptionMessageDoesNotMatchExpected($e, $message)) { |
||
| 57 | throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received"); |
||
| 58 | } |
||
| 59 | } catch (\Exception $e) { |
||
| 60 | if ($throws) { |
||
| 61 | if ($throws !== get_class($e)) { |
||
| 62 | throw new AssertionFailedError("exception '$throws' was expected, but " . get_class($e) . ' was thrown'); |
||
| 63 | } |
||
| 64 | if ($this->exceptionMessageDoesNotMatchExpected($e, $message)) { |
||
| 65 | throw new AssertionFailedError("exception message '$message' was expected, but '" . $e->getMessage() . "' was received"); |
||
| 66 | } |
||
| 67 | } else { |
||
| 68 | throw $e; |
||
| 69 | } |
||
| 70 | } |
||
| 71 | |||
| 72 | if ($throws) { |
||
| 73 | if (isset($e)) { |
||
| 74 | $this->assertTrue(true, 'exception handled'); |
||
| 75 | } else { |
||
| 76 | throw new AssertionFailedError("exception '$throws' was not thrown as expected"); |
||
| 77 | } |
||
| 78 | } |
||
| 79 | } |
||
| 80 | |||
| 105 | } |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVarassignment in line 1 and the$higherassignment in line 2 are dead. The first because$myVaris never used and the second because$higheris always overwritten for every possible time line.