| Conditions | 10 |
| Paths | 5 |
| Total Lines | 53 |
| 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 |
||
| 32 | // reuses 'url' tag with ParseContent = true |
||
| 33 | if ($node->getParent()->getTagName() === 'url') { |
||
| 34 | return $string; |
||
| 35 | } |
||
| 36 | $string = $this->hashLink($string); |
||
| 37 | $string = $this->atUserLink($string); |
||
| 38 | |||
| 39 | return $this->autolink($string); |
||
| 40 | } |
||
| 41 | |||
| 42 | /** |
||
| 43 | * Links @<username> to the user's profile. |
||
| 44 | * |
||
| 45 | * @param string $string The Text to be parsed. |
||
| 46 | * @return string The text with usernames linked. |
||
| 47 | */ |
||
| 48 | protected function atUserLink(string $string): string |
||
| 49 | { |
||
| 50 | $tags = []; |
||
| 51 | |||
| 52 | /* |
||
| 53 | * - '\pP' all unicode punctuation marks |
||
| 54 | * - '<' if nl2br has taken place whatchout for <br /> linebreaks |
||
| 55 | */ |
||
| 56 | $hasTags = preg_match_all('/(\s|^)@([^\s\pP<]+)/m', $string, $tags); |
||
| 57 | if (!$hasTags) { |
||
| 58 | return $string; |
||
| 59 | } |
||
| 60 | |||
| 61 | // would be cleaner to pass userlist by value, but for performance reasons |
||
| 62 | // we only query the db if we actually have any @ tags |
||
| 63 | $users = $this->_sOptions->get('UserList')->get(); |
||
| 64 | sort($users); |
||
| 65 | $names = []; |
||
| 66 | if (empty($tags[2]) === false) { |
||
| 67 | $tags = $tags[2]; |
||
| 68 | foreach ($tags as $tag) { |
||
| 69 | if (in_array($tag, $users)) { |
||
| 70 | $names[$tag] = 1; |
||
| 71 | } else { |
||
| 72 | $continue = 0; |
||
| 73 | foreach ($users as $user) { |
||
| 74 | if (mb_strpos($user, $tag) === 0) { |
||
| 75 | $names[$user] = 1; |
||
| 76 | $continue = true; |
||
| 77 | } |
||
| 78 | if ($continue === false) { |
||
| 79 | break; |
||
| 80 | } elseif ($continue !== 0) { |
||
| 81 | $continue = false; |
||
| 82 | } |
||
| 83 | } |
||
| 84 | } |
||
| 85 | } |
||
| 192 |