Completed
Push — Submit-Comment-Mobile-API ( dc14cd )
by
unknown
74:57 queued 54:25
created

Helpers::signData()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
ccs 0
cts 5
cp 0
crap 2
1
<?php
2
namespace ModPleio;
3
4
class Helpers {
5
    public static function generateUsername($username) {
6
        $hidden = access_show_hidden_entities(true);
7
8
        while (strlen($username) < 4) {
9
            $username .= "0";
10
        }
11
12 View Code Duplication
        if (get_user_by_username($username)) {
13
            $i = 1;
14
15
            while (get_user_by_username($username . $i)) {
16
                $i++;
17
            }
18
19
            $result = $username . $i;
20
        } else {
21
            $result = $username;
22
        }
23
24
        access_show_hidden_entities($hidden);
25
        return $result;
26
    }
27
28
    public static function removeUser(\ElggUser $user) {
29
        if (!$user || !$user instanceof \ElggUser) {
30
            return false;
31
        }
32
33
        // make sure the user cannot login any more, also not with the "rememberme" cookie
34
        $user->ban("banned");
35
        $user->removeAdmin();
36
        $user->save();
37
38
        $result = Helpers::removeAllRelationships($user);
39
        $result &= Helpers::removeAllMetadata($user);
40
        $result &= Helpers::removeAllPrivateSettings($user);
41
        $result &= Helpers::anonymizeAccount($user);
42
43
        return $result;
44
    }
45
46
    public function removeAllRelationships(\ElggUser $user) {
47
        $dbprefix = elgg_get_config("dbprefix");
48
        $result = delete_data("DELETE FROM {$dbprefix}entity_relationships WHERE guid_one = {$user->guid} OR guid_two = {$user->guid}");
49
50
        return ($result !== false);
51
    }
52
53
    public function removeAllMetadata(\ElggUser $user) {
54
        $dbprefix = elgg_get_config("dbprefix");
55
        $result = delete_data("DELETE FROM {$dbprefix}metadata WHERE entity_guid = {$user->guid}");
56
57
        return ($result !== false);
58
    }
59
60
    public function removeAllPrivateSettings(\ElggUser $user) {
61
        $dbprefix = elgg_get_config("dbprefix");
62
        $result = delete_data("DELETE FROM {$dbprefix}private_settings WHERE entity_guid = {$user->guid}");
63
64
        return ($result !== false);
65
    }
66
67
    public static function anonymizeAccount(\ElggUser $user) {
68
        $dbprefix = elgg_get_config("dbprefix");
69
70
        // set site_guid to 0 as we do not want to display the entity in the listing any more
71
        $result = update_data("UPDATE {$dbprefix}entities SET
72
            site_guid = 0
73
            WHERE guid = {$user->guid}"
74
        );
75
76
        $result &= update_data("UPDATE {$dbprefix}users_entity SET 
77
            password = NULL,
78
            salt = NULL,
79
            password_hash = NULL,
80
            name = 'Verwijderde gebruiker',
81
            username = 'verwijderd{$user->guid}',
82
            email = NULL,
83
            pleio_guid = NULL,
84
            language = NULL,
85
            last_action = 0,
86
            prev_last_action = 0,
87
            last_login = 0,
88
            prev_last_login = 0
89
            WHERE guid = {$user->guid}"
90
        );
91
92
        _elgg_invalidate_cache_for_entity($user->guid);
93
94
        if (is_memcache_available()) {
95
            $newentity_cache = new \ElggMemcache("new_entity_cache");
96
            $newentity_cache->delete($user->guid);
97
        }
98
99
        elgg_trigger_event("update", "user", get_entity($user->guid));
0 ignored issues
show
Documentation introduced by
get_entity($user->guid) is of type object<ElggEntity>, but the function expects a string|null.

It seems like the type of the argument is not accepted by the function/method which you are calling.

In some cases, in particular if PHP’s automatic type-juggling kicks in this might be fine. In other cases, however this might be a bug.

We suggest to add an explicit type cast like in the following example:

function acceptsInteger($int) { }

$x = '123'; // string "123"

// Instead of
acceptsInteger($x);

// we recommend to use
acceptsInteger((integer) $x);
Loading history...
100
101
        return ($result !== false);
102
    }
103
}