| Conditions | 20 |
| Paths | 336 |
| Total Lines | 71 |
| Code Lines | 41 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 1 | ||
| Bugs | 0 | Features | 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 usersLoggedInQuery($type = 'nolist'): string |
||
| 69 | { |
||
| 70 | $content = ''; |
||
| 71 | $anonymous = 0; |
||
| 72 | $logged_in = []; |
||
| 73 | |||
| 74 | foreach ($this->user_service->allLoggedIn() as $user) { |
||
| 75 | if (Auth::isAdmin() || $user->getPreference(User::PREF_IS_VISIBLE_ONLINE) === '1') { |
||
| 76 | $logged_in[] = $user; |
||
| 77 | } else { |
||
| 78 | $anonymous++; |
||
| 79 | } |
||
| 80 | } |
||
| 81 | |||
| 82 | $count_logged_in = count($logged_in); |
||
| 83 | |||
| 84 | if ($count_logged_in === 0 && $anonymous === 0) { |
||
| 85 | $content .= I18N::translate('No signed-in and no anonymous users'); |
||
| 86 | } |
||
| 87 | |||
| 88 | if ($anonymous > 0) { |
||
| 89 | $content .= '<b>' . I18N::plural('%s anonymous signed-in user', '%s anonymous signed-in users', $anonymous, I18N::number($anonymous)) . '</b>'; |
||
| 90 | } |
||
| 91 | |||
| 92 | if ($count_logged_in > 0) { |
||
| 93 | if ($anonymous) { |
||
| 94 | if ($type === 'list') { |
||
| 95 | $content .= '<br><br>'; |
||
| 96 | } else { |
||
| 97 | $content .= ' ' . I18N::translate('and') . ' '; |
||
| 98 | } |
||
| 99 | } |
||
| 100 | $content .= '<b>' . I18N::plural('%s signed-in user', '%s signed-in users', $count_logged_in, I18N::number($count_logged_in)) . '</b>'; |
||
| 101 | if ($type === 'list') { |
||
| 102 | $content .= '<ul>'; |
||
| 103 | } else { |
||
| 104 | $content .= ': '; |
||
| 105 | } |
||
| 106 | } |
||
| 107 | |||
| 108 | if (Auth::check()) { |
||
| 109 | foreach ($logged_in as $user) { |
||
| 110 | if ($type === 'list') { |
||
| 111 | $content .= '<li>'; |
||
| 112 | } |
||
| 113 | |||
| 114 | $individual = Registry::individualFactory()->make($this->tree->getUserPreference($user, User::PREF_TREE_ACCOUNT_XREF), $this->tree); |
||
| 115 | |||
| 116 | if ($individual instanceof Individual && $individual->canShow()) { |
||
| 117 | $content .= '<a href="' . e($individual->url()) . '">' . e($user->realName()) . '</a>'; |
||
| 118 | } else { |
||
| 119 | $content .= e($user->realName()); |
||
| 120 | } |
||
| 121 | |||
| 122 | $content .= ' - ' . e($user->userName()); |
||
| 123 | |||
| 124 | if ($user->getPreference(User::PREF_CONTACT_METHOD) !== 'none' && Auth::id() !== $user->id()) { |
||
| 125 | $content .= '<a href="' . e(route(MessagePage::class, ['to' => $user->userName(), 'tree' => $this->tree->name()])) . '" class="btn btn-link" title="' . I18N::translate('Send a message') . '">' . view('icons/email') . '</a>'; |
||
| 126 | } |
||
| 127 | |||
| 128 | if ($type === 'list') { |
||
| 129 | $content .= '</li>'; |
||
| 130 | } |
||
| 131 | } |
||
| 132 | } |
||
| 133 | |||
| 134 | if ($type === 'list') { |
||
| 135 | $content .= '</ul>'; |
||
| 136 | } |
||
| 137 | |||
| 138 | return $content; |
||
| 139 | } |
||
| 284 |