Conditions | 8 |
Paths | 5 |
Total Lines | 56 |
Lines | 10 |
Ratio | 17.86 % |
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 |
||
7 | function convertmycontacts($strcontact) |
||
8 | { |
||
9 | // Ermitteln aller einzelnen Wörter von Kontakt aus Termin piCal |
||
10 | // Umwandeln der einzelnen Namen in Link auf Benutzerkonto, wenn Name ein Mitgliedsname ist |
||
11 | $strsearch = ' '; |
||
12 | $strnew = ''; |
||
13 | $strseperator = ''; |
||
|
|||
14 | |||
15 | $pos1 = 0; |
||
16 | $pos2 = strpos($strcontact, $strsearch, $pos1); |
||
17 | |||
18 | if ($pos2 === false) { |
||
19 | //echo "<br>kein leerzeichen"; |
||
20 | $struser = $strcontact; |
||
21 | $struid = getuid($struser); |
||
22 | View Code Duplication | if ($struid == -1) { |
|
23 | $strnew = $struser; |
||
24 | } else { |
||
25 | $strnew = "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $struid . "' title='" . $struser . "'>" . $struser . '</a>'; |
||
26 | } |
||
27 | } else { |
||
28 | //Leerzeichen vorhanden |
||
29 | while ($pos2 !== false) { |
||
30 | //alle wörter zwischen Leerzeichen ermitteln |
||
31 | $struser = substr($strcontact, $pos1, $pos2 - $pos1); |
||
32 | if (substr($struser, -1) === ',') { |
||
33 | $struser = substr($struser, 0, strlen($struser) - 1); |
||
34 | $strseperator = ', '; |
||
35 | } else { |
||
36 | $strseperator = ' '; |
||
37 | } |
||
38 | $struid = getuid($struser); |
||
39 | if ($struid == -1) { |
||
40 | $strnew = $strnew . $struser . $strseperator; |
||
41 | } else { |
||
42 | $strnew = $strnew . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $struid . "' title='" . $struser . "'>" . $struser . '</a>' . $strseperator; |
||
43 | } |
||
44 | $pos1 = $pos2 + 1; |
||
45 | $pos2 = strpos($strcontact, $strsearch, $pos1); |
||
46 | } |
||
47 | |||
48 | if ($pos2 == 0) { |
||
49 | //Rest ab letztem Leerzeichen einlesen |
||
50 | $struser = substr($strcontact, $pos1); |
||
51 | $struid = getuid($struser); |
||
52 | View Code Duplication | if ($struid == -1) { |
|
53 | $strnew .= $struser; |
||
54 | } else { |
||
55 | $strnew = $strnew . "<a href='" . XOOPS_URL . '/userinfo.php?uid=' . $struid . "' title='" . $struser . "'>" . $struser . '</a>'; |
||
56 | } |
||
57 | } else { |
||
58 | } |
||
59 | } |
||
60 | |||
61 | return $strnew; |
||
62 | } |
||
63 | |||
85 |
This check looks for variable assignements that are either overwritten by other assignments or where the variable is not used subsequently.
Both the
$myVar
assignment in line 1 and the$higher
assignment in line 2 are dead. The first because$myVar
is never used and the second because$higher
is always overwritten for every possible time line.