Conditions | 1 |
Paths | 1 |
Total Lines | 88 |
Code Lines | 40 |
Lines | 0 |
Ratio | 0 % |
Changes | 1 | ||
Bugs | 0 | Features | 1 |
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 |
||
169 | public function testIsValidMediaID() |
||
170 | { |
||
171 | /* |
||
172 | * Should return false if no media ID is passed. |
||
173 | */ |
||
174 | $instagramAccount = new InstagramAccount(); |
||
175 | |||
176 | $this->assertEquals(false, $instagramAccount->isValidMediaID()); |
||
177 | |||
178 | /* |
||
179 | * Should return false if the account ID is unavailable. |
||
180 | */ |
||
181 | $mock = $this->getNewInstagramAccountMock()->makePartial(); |
||
182 | $mock |
||
183 | ->shouldReceive('getInstagramID') |
||
184 | ->withNoArgs() |
||
185 | ->andReturn(null); |
||
186 | |||
187 | $this->assertEquals( |
||
188 | false, |
||
189 | $mock->isValidMediaID('123456789012345678_123') |
||
190 | ); |
||
191 | |||
192 | /* |
||
193 | * Should return false if the media ID is less than 18 digits. |
||
194 | */ |
||
195 | $mock = $this->getNewInstagramAccountMock()->makePartial(); |
||
196 | $mock |
||
197 | ->shouldReceive('getInstagramID') |
||
198 | ->withNoArgs() |
||
199 | ->andReturn('123'); |
||
200 | |||
201 | $this->assertEquals( |
||
202 | false, |
||
203 | $mock->isValidMediaID('12345678901234567_123') |
||
204 | ); |
||
205 | |||
206 | /* |
||
207 | * Should return false if the media ID is greater than 19 digits. |
||
208 | */ |
||
209 | $this->assertEquals( |
||
210 | false, |
||
211 | $mock->isValidMediaID('12345678901234567890_123') |
||
212 | ); |
||
213 | |||
214 | /* |
||
215 | * Should return false if the media ID length is valid but contains non-digits. |
||
216 | */ |
||
217 | $this->assertEquals( |
||
218 | false, |
||
219 | $mock->isValidMediaID('123456789Z12345678_123') |
||
220 | ); |
||
221 | |||
222 | $this->assertEquals( |
||
223 | false, |
||
224 | $mock->isValidMediaID('123456789&12345678_123') |
||
225 | ); |
||
226 | |||
227 | /* |
||
228 | * Should return false if a valid media ID is not followed by an underscore. |
||
229 | */ |
||
230 | $this->assertEquals( |
||
231 | false, |
||
232 | $mock->isValidMediaID('123456789012345678-123') |
||
233 | ); |
||
234 | |||
235 | /* |
||
236 | * Should return false if the media ID doesn't end with the account ID. |
||
237 | */ |
||
238 | $this->assertEquals( |
||
239 | false, |
||
240 | $mock->isValidMediaID('123456789012345678_321') |
||
241 | ); |
||
242 | |||
243 | /* |
||
244 | * Should return true if the media ID is 18 or 19 characters followed by |
||
245 | * an underscore and the account ID. |
||
246 | */ |
||
247 | $this->assertEquals( |
||
248 | true, |
||
249 | $mock->isValidMediaID('123456789012345678_123') |
||
250 | ); |
||
251 | |||
252 | $this->assertEquals( |
||
253 | true, |
||
254 | $mock->isValidMediaID('1234567890123456789_123') |
||
255 | ); |
||
256 | } |
||
257 | } |
||
258 |
You can fix this by adding a namespace to your class:
When choosing a vendor namespace, try to pick something that is not too generic to avoid conflicts with other libraries.