| Conditions | 1 |
| Paths | 1 |
| Total Lines | 58 |
| 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 |
||
| 47 | public function testRequest() |
||
| 48 | { |
||
| 49 | $responseContent = <<<RESP |
||
| 50 | HTTP/1.1 302 FOUND |
||
| 51 | Server: nginx |
||
| 52 | Date: Tue, 09 Feb 2016 11:54:35 GMT |
||
| 53 | Content-Type: text/html; charset=utf-8 |
||
| 54 | Content-Length: 0 |
||
| 55 | Connection: keep-alive |
||
| 56 | Location: get |
||
| 57 | Access-Control-Allow-Origin: * |
||
| 58 | Access-Control-Allow-Credentials: true |
||
| 59 | |||
| 60 | HTTP/1.1 200 OK |
||
| 61 | Server: nginx |
||
| 62 | Date: Tue, 09 Feb 2016 11:54:35 GMT |
||
| 63 | Content-Type: text/html; charset=utf-8 |
||
| 64 | Content-Length: 30 |
||
| 65 | Connection: keep-alive |
||
| 66 | Access-Control-Allow-Origin: * |
||
| 67 | Access-Control-Allow-Credentials: true |
||
| 68 | |||
| 69 | <!doctype html> |
||
| 70 | <html> |
||
| 71 | </html> |
||
| 72 | RESP; |
||
| 73 | $transferInfo = [ |
||
| 74 | 'header_size' => 452, |
||
| 75 | 'http_code' => 200, |
||
| 76 | 'content_type' => 'text/html; charset=utf-8', |
||
| 77 | ]; |
||
| 78 | |||
| 79 | $transport = $this->getMockBuilder('\Jgut\Spiral\Transport\Curl') |
||
| 80 | ->disableOriginalConstructor() |
||
| 81 | ->getMock(); |
||
| 82 | $transport |
||
| 83 | ->expects(static::once()) |
||
| 84 | ->method('request') |
||
| 85 | ->will(static::returnValue($responseContent)); |
||
| 86 | $transport |
||
| 87 | ->expects(static::once()) |
||
| 88 | ->method('responseInfo') |
||
| 89 | ->will(static::returnValue($transferInfo)); |
||
| 90 | $transport |
||
| 91 | ->expects(static::once()) |
||
| 92 | ->method('close'); |
||
| 93 | |||
| 94 | $request = new Request('', 'GET'); |
||
| 95 | $response = new Response; |
||
| 96 | |||
| 97 | $client = new Client($transport); |
||
| 98 | $response = $client->request($request, $response); |
||
| 99 | |||
| 100 | static::assertEquals(200, $response->getStatusCode()); |
||
| 101 | static::assertEquals('nginx', $response->getHeaderLine('Server')); |
||
| 102 | static::assertFalse($response->hasHeader('Location')); |
||
| 103 | static::assertEquals(1, preg_match('/^<!doctype html>/i', $response->getBody())); |
||
| 104 | } |
||
| 105 | } |
||
| 106 |