Passed
Push — master ( c0a3a7...3b84a4 )
by Jeroen
58:51
created

actions/uservalidationbyemail/validate.php (1 issue)

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
foreach ($user_guids as $guid) {
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) {
0 ignored issues
show
It seems like $user_guids can also be of type string; however, parameter $var of count() does only seem to accept Countable|array, maybe add an additional type check? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

33
if (count(/** @scrutinizer ignore-type */ $user_guids) == 1) {
Loading history...
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