Skill::minOwnedCount()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 0
1
<?php
2
class Skill extends CModel
3
{
4
    public function attributeNames()
5
    {
6
        return [];
7
    }
8
9
    public function updateExtended()
10
    {
11
        //calculate
12
        $limitItems = $this->minOwnedCount();
13
        $sumSkill = Yii::app()->player->model->skill;
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...
14
15
        //get items limited
16
        $sumSkill += $this->sumSkill($limitItems, false);
17
18
        //get baits limited
19
        $sumSkill += $this->sumSkill($limitItems, true);
20
        if ($sumSkill < 1) {
21
            $sumSkill = 1; //lowest value for player skill.
22
        }
23
24
        Yii::app()->player->model->rewriteAttributes(['skill_extended'=>$sumSkill]);
25
    }
26
    
27
    private function minOwnedCount()
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...
28
    {
29
        $smaller = Yii::app()->player->model->owned_items < Yii::app()->player->model->owned_baits ? Yii::app()->player->model->owned_items : Yii::app()->player->model->owned_baits;
30
        return $smaller;
31
    }
32
33
    /**
34
     * Reads the max number of items from the database that can be used and sums their skill points.
35
     */
36
    private function sumSkill($limitItems, $isBait = false)
37
    {
38
        $table = $isBait ? 'users_baits' : 'users_items';
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
39
        $skill = 0;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
40
        $countItem = 0;
41
        $loop = 0;
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...
42
        $limit = 10;
0 ignored issues
show
Coding Style introduced by
Equals sign not aligned with surrounding assignments; expected 5 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...
43
        do {
44
            $doLoop = false;
45
            $offset = $loop * $limit;
46
            $res = Yii::app()->db->createCommand()
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...
47
                ->select('item_id, item_count, skill')
48
                ->from($table)
49
                ->where('uid=:uid', [':uid'=>Yii::app()->player->uid])
50
                ->order('skill DESC')
51
                ->offset($offset)
52
                ->limit($limit)
53
                ->queryAll();
54
            foreach ($res as $item) {
55
56
                $toAdd = $limitItems - $countItem;
57
                if ($toAdd > $item['item_count']) {
58
                    $toAdd = $item['item_count'];
59
                }
60
61
                $countItem += $toAdd;
62
63
                if ($toAdd) {
64
                    $skill += $toAdd * $item['skill'];
65
                }
66
67
                $doLoop = $countItem < $limitItems;
68
69
                if (!$doLoop) {
70
                    break;
71
                }
72
            }
73
            $loop++;
74
        } while ($doLoop);
75
76
        return $skill;
77
    }
78
}
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...
79