Badge::attributeNames()   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 $badges
5
 */
6
class Badge extends CModel
7
{
8
    const LEVEL_BRONZE = 1;
9
    const LEVEL_SILVER = 2;
10
    const LEVEL_GOLD = 3;
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...
11
12
    protected $uid;
13
    protected $badges;
14
15
    public function attributeNames()
16
    {
17
        return [];
18
    }
19
20
    public function getUid()
21
    {
22
        return $this->uid;
23
    }
24
25
    public function setUid($uid)
26
    {
27
        $this->uid = (int)$uid;
28
    }
29
30
    public function fetchBadges()
31
    {
32
        $redis = Yii::app()->redis->getClient();
33
        if ($this->badges) {
34
            return false;
35
        }
36
37
        $this->badges = $redis->sMembers('badges:all');
38
    }
39
40
    protected function getBadge($id)
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
        $redis = Yii::app()->redis->getClient();
43
        return $redis->hGetAll("badges:d:$id");
0 ignored issues
show
Coding Style Best Practice introduced by
As per coding-style, please use concatenation or sprintf for the variable $id instead of interpolation.

It is generally a best practice as it is often more readable to use concatenation instead of interpolation for variables inside strings.

// Instead of
$x = "foo $bar $baz";

// Better use either
$x = "foo " . $bar . " " . $baz;
$x = sprintf("foo %s %s", $bar, $baz);
Loading history...
44
    }
45
}
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...
46