These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /** |
||
3 | * Validate a user or users by guid |
||
4 | */ |
||
5 | |||
6 | $user_guids = get_input('user_guids'); |
||
7 | $error = false; |
||
8 | |||
9 | if (!$user_guids) { |
||
10 | return elgg_error_response(elgg_echo('uservalidationbyemail:errors:unknown_users')); |
||
11 | } |
||
12 | |||
13 | $access = access_show_hidden_entities(true); |
||
14 | |||
15 | View Code Duplication | foreach ($user_guids as $guid) { |
|
1 ignored issue
–
show
|
|||
16 | $user = get_entity($guid); |
||
17 | if (!$user instanceof ElggUser) { |
||
18 | $error = true; |
||
19 | continue; |
||
20 | } |
||
21 | |||
22 | // only validate if not validated |
||
23 | $user->setValidationStatus(true, 'manual'); |
||
24 | |||
25 | if ($user->isValidated() !== false || !($user->enable())) { |
||
26 | $error = true; |
||
27 | continue; |
||
28 | } |
||
29 | } |
||
30 | |||
31 | access_show_hidden_entities($access); |
||
32 | |||
33 | if (count($user_guids) == 1) { |
||
34 | $message_txt = elgg_echo('uservalidationbyemail:messages:validated_user'); |
||
35 | $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_user'); |
||
36 | } else { |
||
37 | $message_txt = elgg_echo('uservalidationbyemail:messages:validated_users'); |
||
38 | $error_txt = elgg_echo('uservalidationbyemail:errors:could_not_validate_users'); |
||
39 | } |
||
40 | |||
41 | if ($error) { |
||
42 | return elgg_error_response($error_txt); |
||
43 | } |
||
44 | |||
45 | return elgg_ok_response('', $message_txt); |
||
46 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.