Conditions | 3 |
Paths | 2 |
Total Lines | 23 |
Code Lines | 14 |
Lines | 11 |
Ratio | 47.83 % |
Tests | 0 |
CRAP Score | 12 |
Changes | 0 |
1 | <?php |
||
38 | public function generateUniqueUsername($data) { |
||
39 | $email = $data["email"]; |
||
40 | list($name, $email) = explode("@", $email); |
||
41 | $name = trim($name); |
||
42 | |||
43 | $hidden = access_show_hidden_entities(true); |
||
44 | |||
45 | View Code Duplication | if (get_user_by_username($name)) { |
|
46 | $i = 1; |
||
47 | |||
48 | while (get_user_by_username($name . $i)) { |
||
49 | $i++; |
||
50 | } |
||
51 | |||
52 | $result = $name . $i; |
||
53 | } else { |
||
54 | $result = $name; |
||
55 | } |
||
56 | |||
57 | access_show_hidden_entities($hidden); |
||
58 | |||
59 | return $result; |
||
60 | } |
||
61 | |||
76 | } |
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check:
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue.