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 |
||
65 | function http_build_url( $parsed_url ) { |
||
66 | $scheme = isset( $parsed_url['scheme'] ) ? $parsed_url['scheme'] . '://' : ''; |
||
67 | $host = isset( $parsed_url['host'] ) ? $parsed_url['host'] : ''; |
||
68 | $port = isset( $parsed_url['port'] ) ? ':' . $parsed_url['port'] : ''; |
||
69 | $user = isset( $parsed_url['user'] ) ? $parsed_url['user'] : ''; |
||
70 | $pass = isset( $parsed_url['pass'] ) ? ':' . $parsed_url['pass'] : ''; |
||
71 | $pass = ( $user || $pass ) ? "$pass@" : ''; |
||
72 | $path = isset( $parsed_url['path'] ) ? $parsed_url['path'] : ''; |
||
73 | $query = isset( $parsed_url['query'] ) ? '?' . $parsed_url['query'] : ''; |
||
74 | $fragment = isset( $parsed_url['fragment'] ) ? '#' . $parsed_url['fragment'] : ''; |
||
75 | |||
76 | return "$scheme$user$pass$host$port$path$query$fragment"; |
||
77 | } |
||
78 | } |