Conditions | 1 |
Paths | 1 |
Total Lines | 53 |
Code Lines | 38 |
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 |
||
36 | public function it_should_resolve_arguments( |
||
37 | ReflectionClass $reflectionClass, |
||
38 | ServiceManager $serviceManager |
||
39 | ) { |
||
40 | $arguments = [ |
||
41 | '@Config', |
||
42 | '@My\Example\Service', |
||
43 | '1', |
||
44 | 'simple string', |
||
45 | ]; |
||
46 | |||
47 | $result = [ |
||
48 | '@Config@', |
||
49 | '@My\Example\Service@', |
||
50 | '1', |
||
51 | 'simple string', |
||
52 | ]; |
||
53 | |||
54 | $this->application->getServiceManager() |
||
55 | ->shouldBeCalled() |
||
56 | ->willReturn($serviceManager); |
||
57 | |||
58 | $serviceManager->has() |
||
59 | ->shouldBeCalled() |
||
60 | ->withArguments([ |
||
61 | substr($arguments[0], 1), |
||
62 | ]) |
||
63 | ->willReturn(true); |
||
64 | |||
65 | $serviceManager->get() |
||
66 | ->shouldBeCalled() |
||
67 | ->withArguments([ |
||
68 | substr($arguments[0], 1), |
||
69 | ]) |
||
70 | ->willReturn($result[0]); |
||
71 | |||
72 | $serviceManager->has() |
||
73 | ->shouldBeCalled() |
||
74 | ->withArguments([ |
||
75 | substr($arguments[1], 1), |
||
76 | ]) |
||
77 | ->willReturn(true); |
||
78 | |||
79 | $serviceManager->get() |
||
80 | ->shouldBeCalled() |
||
81 | ->withArguments([ |
||
82 | substr($arguments[1], 1), |
||
83 | ]) |
||
84 | ->willReturn($result[1]); |
||
85 | |||
86 | $this->resolveArguments($reflectionClass, $arguments) |
||
87 | ->shouldReturn($result); |
||
88 | } |
||
89 | } |
||
90 |