Conditions | 1 |
Paths | 1 |
Total Lines | 51 |
Code Lines | 46 |
Lines | 0 |
Ratio | 0 % |
Changes | 2 | ||
Bugs | 1 | 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 |
||
12 | public function testServerRequest() |
||
13 | { |
||
14 | $request = (new ServerRequest(['DOCUMENT_ROOT' => '/www'])) |
||
15 | ->withMethod('GET') |
||
16 | ->withUri(new Uri('http://user:[email protected]/?ola#id')) |
||
17 | ->withQueryParams(['ola' => 'value']) |
||
18 | ->withAttribute('bar', 'foo') |
||
19 | ->withCookieParams(['cookie-name' => 'cookie-value']) |
||
20 | ->withParsedBody(['name' => 'value']) |
||
21 | ->withUploadedFiles([ |
||
22 | 'file' => new UploadedFile('file.jpg', 50, 0, 'file.jpg', 'image/jpg'), |
||
23 | ]) |
||
24 | ->withBody(new Stream('php://temp', 'r')) |
||
25 | ->withHeader('Content-Type', 'text/html'); |
||
26 | |||
27 | Assert::create($request) |
||
28 | ->protocolVersion('1.1') |
||
29 | ->header('Content-Type', 'text/html') |
||
30 | ->hasHeader('Content-Type') |
||
31 | ->hasNotHeader('X-Content-Type') |
||
32 | ->requestTarget('/?ola') |
||
33 | ->uri('http://user:[email protected]/?ola#id') |
||
34 | ->method('GET') |
||
35 | ->attribute('bar', 'foo') |
||
36 | ->hasAttribute('bar') |
||
37 | ->hasParsedBody('name') |
||
38 | ->parsedBody('name', 'value') |
||
39 | ->hasUploadedFile('file') |
||
40 | ->hasQueryParam('ola') |
||
41 | ->queryParam('ola', 'value') |
||
42 | ->cookieParam('cookie-name', 'cookie-value') |
||
43 | ->hasCookieParam('cookie-name') |
||
44 | ->hasServerParam('DOCUMENT_ROOT') |
||
45 | ->serverParam('DOCUMENT_ROOT', '/www') |
||
46 | ->assertUri() |
||
47 | ->scheme('http') |
||
48 | ->authority('user:[email protected]') |
||
49 | ->host('dag.gal') |
||
50 | ->query('ola') |
||
51 | ->fragment('id') |
||
52 | ->path('/') |
||
53 | ->userInfo('user:pass') |
||
54 | ->port(null) |
||
55 | ->end() |
||
56 | |||
57 | ->assertBody() |
||
58 | ->isNotWritable() |
||
59 | ->isReadable() |
||
60 | ->isSeekable() |
||
61 | ->size(0); |
||
62 | } |
||
63 | |||
105 |
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.