Conditions | 1 |
Paths | 1 |
Total Lines | 62 |
Code Lines | 53 |
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 |
||
90 | public function testErrorThatIsNotRetried() |
||
91 | { |
||
92 | $event = m::mock(ErrorEvent::class); |
||
93 | |||
94 | $response = m::mock(ResponseInterface::class); |
||
95 | $event->shouldReceive('getResponse') |
||
96 | ->atLeast() |
||
97 | ->once() |
||
98 | ->andReturn($response); |
||
99 | $response->shouldReceive('getStatusCode') |
||
100 | ->atLeast() |
||
101 | ->once() |
||
102 | ->andReturn(401); |
||
103 | |||
104 | $request = m::mock(RequestInterface::class); |
||
105 | $event->shouldReceive('getRequest') |
||
106 | ->atLeast() |
||
107 | ->once() |
||
108 | ->andReturn($request); |
||
109 | $request->shouldReceive('getScheme') |
||
110 | ->atLeast() |
||
111 | ->once() |
||
112 | ->andReturn('https'); |
||
113 | $config = m::mock(Collection::class); |
||
114 | $request->shouldReceive('getConfig') |
||
115 | ->atLeast() |
||
116 | ->once() |
||
117 | ->andReturn($config); |
||
118 | $config->shouldReceive('get') |
||
119 | ->with('auth') |
||
120 | ->atLeast() |
||
121 | ->once() |
||
122 | ->andReturn('gigya-oauth2'); |
||
123 | $config->shouldReceive('get') |
||
124 | ->with('retried') |
||
125 | ->atLeast() |
||
126 | ->once() |
||
127 | ->andReturn(false); |
||
128 | |||
129 | $token = new AccessToken('test2'); |
||
130 | $this->grant->shouldReceive('getToken') |
||
131 | ->andReturn($token); |
||
132 | |||
133 | $config->shouldReceive('set') |
||
134 | ->with('retried', true) |
||
135 | ->atLeast() |
||
136 | ->once(); |
||
137 | |||
138 | $newResponse = m::mock(ResponseInterface::class); |
||
139 | |||
140 | $event->shouldReceive('getClient->send') |
||
141 | ->with($request) |
||
142 | ->atLeast() |
||
143 | ->once() |
||
144 | ->andReturn($newResponse); |
||
145 | $event->shouldReceive('intercept') |
||
146 | ->atLeast() |
||
147 | ->once() |
||
148 | ->with($newResponse); |
||
149 | |||
150 | $this->subscriber->error($event); |
||
151 | } |
||
152 | |||
230 |