Conditions | 10 |
Paths | 10 |
Total Lines | 29 |
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 |
||
45 | private function prepareInvocationString(string $invoked): PHPUnit_Framework_MockObject_Matcher_Invocation |
||
46 | { |
||
47 | if (preg_match("/(?'method'\w+)(?:\s+(?'count'\d+))?/", $invoked, $matches)) { |
||
48 | $method = $matches['method']; |
||
49 | if (!isset($matches['count'])) { |
||
50 | switch ($method) { |
||
51 | case 'once': |
||
52 | return TestCase::once(); |
||
53 | case 'any': |
||
54 | return TestCase::any(); |
||
55 | case 'never': |
||
56 | return TestCase::never(); |
||
57 | case 'atLeastOnce': |
||
58 | return TestCase::atLeastOnce(); |
||
59 | } |
||
60 | } else { |
||
61 | $count = (int)$matches['count']; |
||
62 | switch ($method) { |
||
63 | case 'atLeast': |
||
64 | return TestCase::atLeast($count); |
||
65 | case 'exactly': |
||
66 | return TestCase::exactly($count); |
||
67 | case 'atMost': |
||
68 | return TestCase::atMost($count); |
||
69 | } |
||
70 | } |
||
71 | } |
||
72 | |||
73 | throw new TestException("prepareInvocationString cannot handle '$invoked'"); |
||
74 | } |
||
76 |