| Conditions | 8 |
| Paths | 6 |
| Total Lines | 55 |
| Code Lines | 32 |
| 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 |
||
| 115 | return true; |
||
| 116 | } |
||
| 117 | |||
| 118 | return $this->checkUserInGroupByFilter($userDn); |
||
| 119 | } |
||
| 120 | |||
| 121 | /** |
||
| 122 | * @param string $userDn |
||
| 123 | * |
||
| 124 | * @return bool |
||
| 125 | * @throws LdapException |
||
| 126 | */ |
||
| 127 | private function checkUserInGroupByFilter(string $userDn): bool |
||
| 128 | { |
||
| 129 | $groupDn = $this->getGroupDn(); |
||
| 130 | |||
| 131 | $filter = '(&(|' |
||
| 132 | . LdapUtil::getAttributesForFilter(self::FILTER_USER_ATTRIBUTES, $userDn) |
||
| 133 | . ')(|' |
||
| 134 | . LdapUtil::getAttributesForFilter(self::FILTER_GROUP_ATTRIBUTES, $groupDn) |
||
| 135 | . '))'; |
||
| 136 | |||
| 137 | $searchResults = $this->ldapActions->getObjects($filter, ['dn']); |
||
| 138 | |||
| 139 | if (isset($searchResults['count']) |
||
| 140 | && (int)$searchResults['count'] === 0 |
||
| 141 | ) { |
||
| 142 | $this->eventDispatcher->notifyEvent('ldap.check.group', |
||
| 143 | new Event($this, EventMessage::factory() |
||
| 144 | ->addDescription(__u('Usuario no pertenece al grupo')) |
||
| 145 | ->addDetail(__u('Usuario'), $userDn) |
||
| 146 | ->addDetail(__u('Grupo'), $groupDn) |
||
| 147 | ->addDetail('LDAP FILTER', $filter))); |
||
| 148 | |||
| 149 | return false; |
||
| 150 | } |
||
| 151 | |||
| 152 | $this->eventDispatcher->notifyEvent('ldap.check.group', |
||
| 153 | new Event($this, EventMessage::factory() |
||
| 154 | ->addDescription(__u('Usuario verificado en grupo')) |
||
| 155 | ->addDetail(__u('Usuario'), $userDn) |
||
| 156 | ->addDetail(__u('Grupo'), $groupDn))); |
||
| 157 | |||
| 158 | return true; |
||
| 159 | } |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Obtener el servidor de LDAP a utilizar |
||
| 163 | * |
||
| 164 | * @return mixed |
||
| 165 | */ |
||
| 166 | protected function pickServer() |
||
| 167 | { |
||
| 168 | $server = $this->ldapParams->getServer(); |
||
| 169 | |||
| 170 | if (preg_match(Address::PATTERN_IP_ADDRESS, $server)) { |
||
| 211 | } |
If you suppress an error, we recommend checking for the error condition explicitly: