PlayerStats::getStats()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
/**
3
 * @property integer $uid
4
 * @property array $stats
5
 */
6
class PlayerStats extends CModel
7
{
8
    private $uid;
9
    private $stats = [
10
        'completed_missions'=>0,
11
        'visited_waters'=>0,
12
        'visited_counties'=>0,
13
        'owned_setitems'=>0,
14
        'setitems'=>[],
15
        'items'=>[],
16
        'baits'=>[],
17
        'sets'=>[],
18
        'counties'=>[],
19
        ];
20
21
    public function attributeNames()
22
    {
23
        return [];
24
    }
25
26
    public function getUid()
27
    {
28
        return $this->uid;
29
    }
30
31
    public function getStats()
32
    {
33
        return $this->stats;
34
    }
35
36
    public function setUid($uid)
37
    {
38
        $this->uid = (int)$uid;
39
    }
40
41
    public function fetchStats()
42
    {
43
        $this->fetchCompletedMissions();
44
        $this->fetchVisitedMissions();
45
        $this->fetchDuel();
46
        $this->fetchCountSets();
47
        $this->fetchItems();
48
        $this->fetchBaits();
49
        $this->fetchSets();
50
        $this->fetchRank();
51
    }
52
53
    protected function fetchCompletedMissions()
54
    {
55
        $res = Yii::app()->db->createCommand()
56
            ->select('COUNT(*)')
57
            ->from('users_missions')
58
            ->where('uid=:uid', [':uid'=>$this->uid])
59
            ->queryScalar();
60
61
        $this->stats['completed_missions'] = $res;
62
    }
63
64
    protected function fetchVisitedMissions()
65
    {
66
        $res = Yii::app()->db->createCommand()
67
            ->select('v.*, w.county_id, w.title')
68
            ->from('visited v')
69
            ->join('waters w', 'v.water_id=w.id')
70
            ->where('v.uid=:uid', [':uid'=>$this->uid])
71
            ->order('v.water_id')
72
            ->queryAll();
73
74
        foreach ($res as $dat) {
75
            $this->stats['routine'][$dat['water_id']] = $dat['routine'];
76
            $this->stats['visited_waters']++;
77
            if (!array_key_exists($dat['county_id'], $this->stats['counties'])) {
78
                $this->stats['visited_counties']++;
79
            }
80
            $this->stats['counties'][$dat['county_id']] = 1;
81
        }
82
    }
83
84
    protected function fetchDuel()
85
    {
86
        $logger = new Logger;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 6 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...
87
        $logger->uid = $this->uid;
0 ignored issues
show
Bug introduced by
The property uid cannot be accessed from this context as it is declared private in class Logger.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
88
        $stat = $logger->getCounters();
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
89
90
        //duels
91
        $this->stats['duel_success'] = @(int)$stat['duel_success'];
92
        $this->stats['duel_fail'] = @(int)$stat['duel_fail'];
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
93
        $this->stats['duel_rate'] = '?';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 4 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...
94
        if ($this->stats['duel_success'] || $this->stats['duel_fail']) {
95
            $this->stats['duel_rate'] = round($this->stats['duel_success'] / (($this->stats['duel_success'] + $this->stats['duel_fail'])/100), 1);
96
        }
97
    }
98
99
    protected function fetchCountSets()
100
    {
101
        $res = Yii::app()->db->createCommand()
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 2 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...
102
            ->select('item_id, item_count')
103
            ->from('users_items')
104
            ->where('uid=:uid AND item_id>999 AND item_count>0', [':uid'=>$this->uid])
105
            ->order('skill DESC, item_id DESC')
106
            ->queryAll();
107
        $best = 0;
108
        foreach ($res as $dat) {
109
            if ($best < 3 && $dat['item_count']) {
110
                $this->stats['setitems'][$dat['item_id']] = $dat['item_count'];
111
                $best++;
112
            }
113
            $this->stats['owned_setitems'] += $dat['item_count'];
114
        }
115
    }
116
117 View Code Duplication
    protected function fetchItems()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
118
    {
119
        $res = Yii::app()->db->createCommand()
120
            ->select('item_id')
121
            ->from('users_items')
122
            ->where('uid=:uid AND item_id < 1000', [':uid'=>$this->uid])
123
            ->order('skill DESC')
124
            ->limit(3)
125
            ->queryAll();
126
        foreach ($res as $dat) {
127
            $i = new Item;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
128
            $i->item_type = Item::TYPE_ITEM;
0 ignored issues
show
Bug introduced by
The property item_type cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
129
            $i->id = $dat['item_id'];
0 ignored issues
show
Bug introduced by
The property id cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
130
            $i->fetch();
131
            $this->stats['items'][] = $i->title;
0 ignored issues
show
Bug introduced by
The property title cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
132
        }
133
    }
134
135 View Code Duplication
    protected function fetchBaits()
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

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.

Loading history...
136
    {
137
        $res = Yii::app()->db->createCommand()
138
            ->select('item_id')
139
            ->from('users_baits')
140
            ->where('uid=:uid', [':uid'=>$this->uid])
141
            ->order('skill DESC')
142
            ->limit(3)
143
            ->queryAll();
144
        foreach ($res as $dat) {
145
            $i = new Item;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
146
            $i->item_type = Item::TYPE_BAIT;
0 ignored issues
show
Bug introduced by
The property item_type cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
147
            $i->id = $dat['item_id'];
0 ignored issues
show
Bug introduced by
The property id cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
148
            $i->fetch();
149
            $this->stats['baits'][] = $i->title;
0 ignored issues
show
Bug introduced by
The property title cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
150
        }
151
    }
152
153
    protected function fetchSets()
154
    {
155
        foreach ($this->stats['setitems'] as $dat => $cnt) {
156
            $i = new Item;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 12 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...
157
            $i->item_type = Item::TYPE_ITEMSET;
0 ignored issues
show
Bug introduced by
The property item_type cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
158
            $i->id = (int)$dat;
0 ignored issues
show
Bug introduced by
The property id cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 8 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...
159
            $i->fetchSet();
160
            $this->stats['sets'][] = $i->title;
0 ignored issues
show
Bug introduced by
The property title cannot be accessed from this context as it is declared private in class Item.

This check looks for access to properties that are not accessible from the current context.

If you need to make a property accessible to another context you can either raise its visibility level or provide an accessible getter in the defining class.

Loading history...
161
        }
162
    }
163
164
    protected function fetchRank()
165
    {
166
        $redis = Yii::app()->redis->getClient();
167
168
        $rank  = $redis->zRevRank('board_p:'.date('Ym'), $this->uid);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 22 spaces but found 2 spaces

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...
169
        $this->stats['rankActual'] = $rank === false ? false : ++$rank;
170
171
        $rank  = $redis->zRevRank('board_p:6month', $this->uid);
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 16 spaces but found 2 spaces

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...
172
        $this->stats['rank'] = $rank === false ? false : ++$rank;
173
    }
174
}
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...
175