| Conditions | 12 |
| Paths | 12 |
| Total Lines | 66 |
| Code Lines | 46 |
| 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 |
||
| 68 | private function extractComments(string $email): string |
||
| 69 | { |
||
| 70 | $result = ''; |
||
| 71 | $inComment = false; |
||
| 72 | $commentDepth = 0; |
||
| 73 | $currentComment = ''; |
||
| 74 | $escaped = false; |
||
| 75 | |||
| 76 | for ($i = 0, $iMax = strlen($email); $i < $iMax; $i++) { |
||
| 77 | $char = $email[$i]; |
||
| 78 | |||
| 79 | if ($escaped) { |
||
| 80 | if ($inComment) { |
||
| 81 | $currentComment .= $char; |
||
| 82 | } else { |
||
| 83 | $result .= $char; |
||
| 84 | } |
||
| 85 | $escaped = false; |
||
| 86 | continue; |
||
| 87 | } |
||
| 88 | |||
| 89 | if ($char === '\\') { |
||
| 90 | $escaped = true; |
||
| 91 | if ($inComment) { |
||
| 92 | $currentComment .= $char; |
||
| 93 | } else { |
||
| 94 | $result .= $char; |
||
| 95 | } |
||
| 96 | continue; |
||
| 97 | } |
||
| 98 | |||
| 99 | if ($char === '(') { |
||
| 100 | if ($inComment) { |
||
| 101 | $commentDepth++; |
||
| 102 | $currentComment .= $char; |
||
| 103 | } else { |
||
| 104 | $inComment = true; |
||
| 105 | $commentDepth = 1; |
||
| 106 | } |
||
| 107 | continue; |
||
| 108 | } |
||
| 109 | |||
| 110 | if ($char === ')') { |
||
| 111 | if ($inComment) { |
||
| 112 | $commentDepth--; |
||
| 113 | if ($commentDepth === 0) { |
||
| 114 | $this->comments[] = $currentComment; |
||
| 115 | $currentComment = ''; |
||
| 116 | $inComment = false; |
||
| 117 | } else { |
||
| 118 | $currentComment .= $char; |
||
| 119 | } |
||
| 120 | } else { |
||
| 121 | $result .= $char; |
||
| 122 | } |
||
| 123 | continue; |
||
| 124 | } |
||
| 125 | |||
| 126 | if ($inComment) { |
||
| 127 | $currentComment .= $char; |
||
| 128 | } else { |
||
| 129 | $result .= $char; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | |||
| 133 | return $result; |
||
| 134 | } |
||
| 230 |