| Conditions | 5 |
| Paths | 3 |
| Total Lines | 17 |
| Code Lines | 12 |
| Lines | 0 |
| Ratio | 0 % |
| Tests | 12 |
| CRAP Score | 5 |
| Changes | 0 | ||
| 1 | <?php |
||
| 24 | 4 | public function is_username_available(array $fields) |
|
| 25 | { |
||
| 26 | 4 | if (!empty($fields["username"])) { |
|
| 27 | 4 | $mc = new midgard_collector('midgard_user', 'login', $fields["username"]); |
|
| 28 | 4 | $mc->set_key_property('person'); |
|
| 29 | 4 | $mc->add_constraint('authtype', '=', midcom::get()->config->get('auth_type')); |
|
| 30 | 4 | $mc->execute(); |
|
| 31 | 4 | $keys = $mc->list_keys(); |
|
| 32 | 4 | if ( count($keys) > 0 |
|
| 33 | 3 | && ( !isset($fields['person']) |
|
| 34 | 4 | || key($keys) != $fields['person'])) { |
|
| 35 | return [ |
||
| 36 | 2 | "username" => sprintf(midcom::get()->i18n->get_string("username %s is already in use", "midgard.admin.user"), $fields['username']) |
|
| 37 | ]; |
||
| 38 | } |
||
| 39 | } |
||
| 40 | 3 | return true; |
|
| 41 | } |
||
| 43 |