Help   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 72
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 0
dl 0
loc 72
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A attributeNames() 0 4 1
A getItems() 0 4 1
A getTopics() 0 4 1
A getRandomItemByType() 0 9 1
A setTopic() 0 4 1
B fetchItems() 0 17 5
A fetchMax() 0 5 1
1
<?php
2
/**
3
 * @property array $items
4
 * @property array $topics
5
 * @property string $topic
6
 * @property string $randomItemByType
7
 */
8
class Help extends CModel
9
{
10
    const TYPE_PROFILE = 1;
11
    const TYPE_MISSION = 2;
12
    const TYPE_SHOP = 3;
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...
13
    const TYPE_DUEL = 4;
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...
14
15
    private $items = [];
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...
16
    private $topics = [
17
        'profile' => 'Profil',
18
        'mission' => 'Megbízások',
19
        'shop' => 'Áron bá',
20
        'duel' => 'Párbaj',
21
        'club' => 'Klubok'
22
        ];
23
    private $topic = 'profile';
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...
24
25
    public function attributeNames()
26
    {
27
        return [];
28
    }
29
30
    public function getItems()
31
    {
32
        return $this->items;
33
    }
34
35
    public function getTopics()
36
    {
37
        return $this->topics;
38
    }
39
40
    public function getRandomItemByType()
0 ignored issues
show
Documentation introduced by
The return type could not be reliably inferred; please add a @return annotation.

Our type inference engine in quite powerful, but sometimes the code does not provide enough clues to go by. In these cases we request you to add a @return annotation as described here.

Loading history...
41
    {
42
        $this->fetchItems(5);
43
        $items = $this->items;
44
        
45
        $rnd = array_rand($items);
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...
46
        $selected = $items[$rnd];
47
        return $selected;
48
    }
49
50
    public function setTopic($topic)
51
    {
52
        $this->topic = $topic;
53
    }
54
55
    public function fetchItems($limit = 0)
56
    {
57
        $max = min(Yii::app()->player->model->level, $this->fetchMax());
58
59
        $this->items = []; //reset
60
        $added = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 7 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...
61
        for ($i=$max; $i>=0; $i--) {
62
            $res = Yii::app()->redis->getClient()->get('help:' . $this->topic . ':'.$i);
63
            if ($res) {
64
                $this->items[$i] = $res;
65
                $added++;
66
                if ($limit>0 && $added>=$limit) {
67
                    break;
68
                }
69
            }
70
        }
71
    }
72
    
73
74
    private function fetchMax()
75
    {
76
        return (int)Yii::app()->redis->getClient()
77
            ->get('help:' . $this->topic . ':max');
78
    }
79
}
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...
80