Conditions | 10 |
Paths | 14 |
Total Lines | 22 |
Code Lines | 15 |
Lines | 8 |
Ratio | 36.36 % |
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 |
||
22 | $link = explode('#', $link)[0]; |
||
23 | |||
24 | if (empty($link)) { |
||
25 | return ''; |
||
26 | } |
||
27 | |||
28 | if (preg_match('~^mailto:|tel:.*~i', $link)) { |
||
29 | return ''; |
||
30 | } elseif (preg_match('~^https?://[^/].*~i', $link)) { |
||
31 | return $link; |
||
32 | } |
||
33 | |||
34 | $isProtocolRelative = preg_match('~^//[^/].*~', $link); |
||
35 | |||
36 | $isSiteRelative = preg_match('~^/[^/].*~', $link); |
||
37 | $isMainPage = $link == '/'; |
||
38 | |||
39 | $components = parse_url($base); |
||
40 | if (empty($components['scheme']) || empty($components['host'])) { |
||
41 | throw new \InvalidArgumentException('Wrong base value'); |
||
42 | } |
||
43 | $scheme = $components['scheme']; |
||
44 | $host = $components['host']; |
||
58 | } |
Adding explicit visibility (
private
,protected
, orpublic
) is generally recommend to communicate to other developers how, and from where this method is intended to be used.