CommonBadgeActivator   A
last analyzed

Complexity

Total Complexity 33

Size/Duplication

Total Lines 125
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 0
Metric Value
wmc 33
lcom 1
cbo 1
dl 0
loc 125
rs 9.3999
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A triggerTravel() 0 14 4
A triggerLocationRoutine() 0 19 4
B triggerSimple() 0 22 6
A triggerRoutine() 0 6 2
A triggerSetPart() 0 8 3
A triggerItems() 0 6 2
A triggerBaits() 0 6 2
A triggerSet() 0 10 4
A triggerClubMembers() 0 6 2
A triggerLoginDays() 0 9 3
A getLoginDays() 0 6 1
1
<?php
2
class CommonBadgeActivator extends BadgeActivator
3
{
4
    public function triggerTravel($id)
5
    {
6
        if ($id == 3) {
7
            $this->activate('travel_loc3');
8
        }
9
10
        if ($id == 5) {
11
            $this->activate('travel_county2');
12
        }
13
14
        if ($id == 33) {
15
            $this->activate('travel_county9');
16
        }
17
    }
18
19
    public function triggerLocationRoutine($id, $routine)
20
    {
21
        $map = [
22
            '4b' => [4, 1],
23
            '13s' => [13, 3],
24
            '28s' => [28, 3],
25
            '37g' => [37, 9],
26
            '52b' => [52, 1],
27
            '61s' => [61, 3],
28
            '71g' => [71, 9],
29
            '72e' => [72, 27],
30
            '46d' => [46, 81]
31
            ];
32
        foreach ($map as $key => $params) {
33
            if ($id == $params[0] && $routine >= $params[1]) {
34
                $this->activate('loc_routine_' . $key);
35
            }
36
        }
37
    }
38
39
    public function triggerSimple($id)
40
    {
41
        $activate = false;
42
        switch ($id) {
43
            case 'energy_drink':
44
                $activate = true;
45
                break;
46
            case 'win_contest':
47
                $activate = true;
48
                break;
49
            case 'club_join':
50
                $activate = true;
51
                break;
52
            case 'club_create':
53
                $activate = true;
54
                break;
55
        }
56
57
        if ($activate) {
58
            $this->activate($id);
59
        }
60
    }
61
62
    public function triggerRoutine($routine)
63
    {
64
        if ($routine >= 100) {
65
            $this->activate('routine_100');
66
        }
67
    }
68
69
    public function triggerSetPart($part)
70
    {
71
        foreach ([3, 10, 30] as $cnt) {
72
            if ($part >= $cnt) {
73
                $this->activate('setpart_' . $cnt);
74
            }
75
        }
76
    }
77
78
    public function triggerItems($cnt)
79
    {
80
        if ($cnt >= 10) {
81
            $this->activate('shop_item10');
82
        }
83
    }
84
85
    public function triggerBaits($cnt)
86
    {
87
        if ($cnt >= 20) {
88
            $this->activate('shop_bait20');
89
        }
90
    }
91
92
    public function triggerSet($id, $sold = false)
93
    {
94
        $key = $sold ? 'set_sell_': 'set_';
95
96
        foreach ([1 => 'b', 2 => 's', 3 => 'g'] as $search => $type) {
97
            if ($id == $search) {
98
                $this->activate($key . $type);
99
            }
100
        }
101
    }
102
103
    public function triggerClubMembers($cnt)
104
    {
105
        if ($cnt >= 8) {
106
            $this->activate('club_members_8');
107
        }
108
    }
109
110
    public function triggerLoginDays()
111
    {
112
        $cnt = $this->getLoginDays();
113
        foreach ([7, 30, 60] as $limit) {
114
            if ($cnt >= $limit) {
115
                $this->activate('login_days_' . $limit);
116
            }
117
        }
118
    }
119
120
    private function getLoginDays()
121
    {
122
        $redis = Yii::app()->redis->getClient();
123
        $key = "counter:login:days:".$this->uid;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 3 spaces but found 1 space

This check looks for multiple assignments in successive lines of code. It will report an issue if the operators are not in a straight line.

To visualize

$a = "a";
$ab = "ab";
$abc = "abc";

will produce issues in the first and second line, while this second example

$a   = "a";
$ab  = "ab";
$abc = "abc";

will produce no issues.

Loading history...
Coding Style Comprehensibility introduced by
The string literal counter:login:days: does not require double quotes, as per coding-style, please use single quotes.

PHP provides two ways to mark string literals. Either with single quotes 'literal' or with double quotes "literal". The difference between these is that string literals in double quotes may contain variables with are evaluated at run-time as well as escape sequences.

String literals in single quotes on the other hand are evaluated very literally and the only two characters that needs escaping in the literal are the single quote itself (\') and the backslash (\\). Every other character is displayed as is.

Double quoted string literals may contain other variables or more complex escape sequences.

<?php

$singleQuoted = 'Value';
$doubleQuoted = "\tSingle is $singleQuoted";

print $doubleQuoted;

will print an indented: Single is Value

If your string literal does not contain variables or escape sequences, it should be defined using single quotes to make that fact clear.

For more information on PHP string literals and available escape sequences see the PHP core documentation.

Loading history...
124
        return (int)$redis->hGet($key, 'cnt');
125
    }
126
}
0 ignored issues
show
Coding Style introduced by
As per coding style, files should not end with a newline character.

This check marks files that end in a newline character, i.e. an empy line.

Loading history...
127