Conditions | 14 |
Paths | 577 |
Total Lines | 39 |
Code Lines | 30 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 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 |
||
35 | public function testConfigure() { |
||
36 | /** @var m\Mock|Command $command */ |
||
37 | $command = m::mock(Command::class); |
||
38 | |||
39 | $expectations = $this->getExpectations(); |
||
40 | foreach ($expectations as $func => $expectation) { |
||
41 | $func = isset($expectation['name']) ? $expectation['name'] : $func; |
||
42 | $times = isset($expectation['times']) ? $expectation['times'] : 1; |
||
43 | $with = !empty($expectation['with']) ? $expectation['with'] : null; |
||
44 | $return = isset($expectations['return']) ? $expectations['return'] : '!self'; |
||
45 | $exp = $command->shouldReceive($func); |
||
46 | if (null !== $times) { |
||
47 | $exp = $exp->times($times); |
||
48 | } |
||
49 | if (null !== $with) { |
||
50 | if (!is_array($with)) { |
||
51 | $with = [$with]; |
||
52 | } |
||
53 | $exp = call_user_func_array([$exp, 'with'], $with); |
||
54 | } |
||
55 | switch ($return) { |
||
56 | case '!self': |
||
57 | $exp->andReturnSelf(); |
||
58 | break; |
||
59 | case '!null': |
||
60 | case null: |
||
61 | $exp->andReturnNull(); |
||
62 | break; |
||
63 | default: |
||
64 | if (is_array($return)) { |
||
65 | $exp->andReturnValues($return); |
||
66 | } elseif (is_callable($return)) { |
||
67 | $exp->andReturnUsing($return); |
||
68 | } |
||
69 | break; |
||
70 | } |
||
71 | } |
||
72 | forward_static_call([$this->getClassName(), 'configure'], $command); |
||
73 | } |
||
74 | |||
100 |