Conditions | 17 |
Paths | 258 |
Total Lines | 62 |
Code Lines | 44 |
Lines | 6 |
Ratio | 9.68 % |
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 |
||
19 | function smarty_modifier_hyperlink($text) |
||
20 | { |
||
21 | $texti = mb_strtolower($text); |
||
22 | $returnValue = ''; |
||
23 | $curPos = 0; |
||
24 | $startHttp = mb_strpos($texti, 'http://', $curPos); |
||
25 | $startHttps = mb_strpos($texti, 'https://', $curPos); |
||
26 | View Code Duplication | if ($startHttp === false || ($startHttps !== false && $startHttps < $startHttp)) { |
|
27 | $startHttp = $startHttps; |
||
28 | } |
||
29 | $endHttp = false; |
||
30 | while (($startHttp !== false) || ($endHttp >= mb_strlen($text))) { |
||
31 | $endHttp1 = mb_strpos($text, ' ', $startHttp); |
||
32 | if ($endHttp1 === false) { |
||
33 | $endHttp1 = mb_strlen($text); |
||
34 | } |
||
35 | $endHttp2 = mb_strpos($text, "\n", $startHttp); |
||
36 | if ($endHttp2 === false) { |
||
37 | $endHttp2 = mb_strlen($text); |
||
38 | } |
||
39 | $endHttp3 = mb_strpos($text, "\r", $startHttp); |
||
40 | if ($endHttp3 === false) { |
||
41 | $endHttp3 = mb_strlen($text); |
||
42 | } |
||
43 | $endHttp4 = mb_strpos($text, '<', $startHttp); |
||
44 | if ($endHttp4 === false) { |
||
45 | $endHttp4 = mb_strlen($text); |
||
46 | } |
||
47 | $endHttp5 = mb_strpos($text, '] ', $startHttp); |
||
48 | if ($endHttp5 === false) { |
||
49 | $endHttp5 = mb_strlen($text); |
||
50 | } |
||
51 | $endHttp6 = mb_strpos($text, ')', $startHttp); |
||
52 | if ($endHttp6 === false) { |
||
53 | $endHttp6 = mb_strlen($text); |
||
54 | } |
||
55 | $endHttp7 = mb_strpos($text, '. ', $startHttp); |
||
56 | if ($endHttp7 === false) { |
||
57 | $endHttp7 = mb_strlen($text); |
||
58 | } |
||
59 | |||
60 | $endHttp = min($endHttp1, $endHttp2, $endHttp3, $endHttp4, $endHttp5, $endHttp6, $endHttp7); |
||
61 | |||
62 | $returnValue .= mb_substr($text, $curPos, $startHttp - $curPos); |
||
63 | $url = mb_substr($text, $startHttp, $endHttp - $startHttp); |
||
64 | $returnValue .= '<a href="' . $url . '" alt="" target="_blank">' . $url . '</a>'; |
||
65 | |||
66 | $curPos = $endHttp; |
||
67 | if ($curPos >= mb_strlen($text)) { |
||
68 | break; |
||
69 | } |
||
70 | $startHttp = mb_strpos(mb_strtolower($text), 'http://', $curPos); |
||
71 | $startHttps = mb_strpos($texti, 'https://', $curPos); |
||
72 | View Code Duplication | if ($startHttp === false || ($startHttps !== false && $startHttps < $startHttp)) { |
|
73 | $startHttp = $startHttps; |
||
74 | } |
||
75 | } |
||
76 | |||
77 | $returnValue .= mb_substr($text, $curPos); |
||
78 | |||
79 | return $returnValue; |
||
80 | } |
||
81 |