Completed
Push — master ( e72458...99f4f0 )
by Karthik
15:24
created

ItemCode::getBinding()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
namespace cyberinferno\Cabal\Helpers;
4
5
/**
6
 * Class ItemCode
7
 *
8
 * Contains methods helpful to generate item code
9
 *
10
 * @package cyberinferno\Cabal\Helpers
11
 * @author Karthik P
12
 */
13
class ItemCode
14
{
15
    const ITEM_GRADE_CONSTANT = 8192;
16
    const ITEM_BIND_ACCOUNT_CONSTANT = 4096;
17
    const ITEM_BIND_CHARACTER_CONSTANT = 524288;
18
    const ITEM_BIND_CHARACTER_ON_USAGE_CONSTANT = 1572864;
19
20
    const MIN_GRADE = 0;
21
    const MAX_GRADE = 15;
22
23
    /**
24
     * @var int
25
     */
26
    protected $_itemCode;
27
    protected $_itemGrade = 0;
28
    protected $_itemBinding = 0;
29
30
    /**
31
     * Item constructor.
32
     *
33
     * @param $itemCode
34
     */
35
    public function __construct($itemCode)
36
    {
37
        $this->_itemCode = $itemCode;
38
    }
39
40
    /**
41
     * Returns the item code
42
     *
43
     * @return int
44
     */
45
    public function getItemCode()
46
    {
47
        return $this->_itemCode;
48
    }
49
50
    /**
51
     * Returns the current grade of the item
52
     *
53
     * @return int
54
     */
55
    public function getGrade()
56
    {
57
        return $this->_itemGrade;
58
    }
59
60
    /**
61
     * Sets the grade of the item to generated
62
     *
63
     * @param int $value
64
     * @return ItemCode $this
65
     */
66
    public function setGrade($value)
67
    {
68
        $value = (int)$value;
69
        if ($value < self::MIN_GRADE) {
70
            $value = self::MIN_GRADE;
71
        }
72
        if ($value > self::MAX_GRADE) {
73
            $value = self::MAX_GRADE;
74
        }
75
        $this->_itemGrade = $value;
76
        return $this;
77
    }
78
79
    /**
80
     * Returns current item binding
81
     *
82
     * @return int
83
     */
84
    public function getBinding()
85
    {
86
        return $this->_itemBinding;
87
    }
88
89
    /**
90
     * Sets the item binding to account
91
     *
92
     * @return ItemCode $this
93
     */
94
    public function setAccountBinding()
95
    {
96
        $this->_itemBinding = self::ITEM_BIND_ACCOUNT_CONSTANT;
97
        return $this;
98
    }
99
100
    /**
101
     * Sets the item binding to character
102
     *
103
     * @return ItemCode $this
104
     */
105
    public function setCharacterBinding()
106
    {
107
        $this->_itemBinding = self::ITEM_BIND_CHARACTER_CONSTANT;
108
        return $this;
109
    }
110
111
    /**
112
     * Sets the item binding to character binding on usage
113
     *
114
     * @return ItemCode $this
115
     */
116
    public function setCharacterBindingOnUsage()
117
    {
118
        $this->_itemBinding = self::ITEM_BIND_CHARACTER_ON_USAGE_CONSTANT;
119
        return $this;
120
    }
121
122
    /**
123
     * Removes the item binding
124
     *
125
     * @return ItemCode $this
126
     */
127
    public function setNoBinding()
128
    {
129
        $this->_itemBinding = 0;
130
        return $this;
131
    }
132
133
    /**
134
     * Returns the generated item code based up on the criteria set
135
     *
136
     * @return int
137
     */
138
    public function generate()
139
    {
140
        return $this->_itemCode + $this->_itemBinding + $this->_itemGrade * self::ITEM_GRADE_CONSTANT;
141
    }
142
}