Conditions | 11 |
Paths | 11 |
Total Lines | 26 |
Lines | 0 |
Ratio | 0 % |
Tests | 23 |
CRAP Score | 11 |
Changes | 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 |
||
9 | 11 | private function getValueFromUrlPlaceholder($name, UriInterface $uri) |
|
10 | { |
||
11 | switch ($name) { |
||
12 | 11 | case 'full': |
|
13 | 11 | case null: |
|
14 | 2 | return $uri->__toString(); |
|
15 | 9 | case 'host': |
|
16 | 1 | return $uri->getHost(); |
|
17 | 8 | case 'scheme': |
|
18 | 1 | return $uri->getScheme(); |
|
19 | 7 | case 'authority': |
|
20 | 1 | return $uri->getAuthority(); |
|
21 | 6 | case 'fragment': |
|
22 | 1 | return $uri->getFragment(); |
|
23 | 5 | case 'path': |
|
24 | 1 | return $uri->getPath(); |
|
25 | 4 | case 'port': |
|
26 | 1 | return $uri->getPort(); |
|
27 | 3 | case 'query': |
|
28 | 1 | return $uri->getQuery(); |
|
29 | 2 | case 'user-info': |
|
30 | 1 | return $uri->getUserInfo(); |
|
31 | 1 | default: |
|
32 | 1 | throw new \Exception('Invalid config'); |
|
33 | 1 | } |
|
34 | } |
||
35 | } |
||
36 |