Conditions | 11 |
Paths | 1024 |
Total Lines | 13 |
Code Lines | 11 |
Lines | 0 |
Ratio | 0 % |
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 |
||
16 | function http_build_url( $parsed_url ) { |
||
17 | $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : ''; |
||
18 | $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : ''; |
||
19 | $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : ''; |
||
20 | $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : ''; |
||
21 | $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : ''; |
||
22 | $pass = ( $user || $pass ) ? "$pass@" : ''; |
||
23 | $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : ''; |
||
24 | $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : ''; |
||
25 | $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : ''; |
||
26 | |||
27 | return "$scheme$user$pass$host$port$path$query$fragment"; |
||
28 | } |
||
29 | } |
||
50 |