InventoryItem   A
last analyzed

Complexity

Total Complexity 10

Size/Duplication

Total Lines 122
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 2
dl 0
loc 122
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A getId() 0 4 1
A getUser() 0 4 1
A getItem() 0 4 1
A getQuantity() 0 4 1
A setQuantity() 0 4 1
A getSlot() 0 4 1
A setSlot() 0 8 2
A removeSlot() 0 4 1
1
<?php
2
3
namespace Rottenwood\KingdomBundle\Entity;
4
5
use Doctrine\ORM\Mapping as ORM;
6
use Rottenwood\KingdomBundle\Entity\Infrastructure\Item;
7
use Rottenwood\KingdomBundle\Entity\Infrastructure\User;
8
use Rottenwood\KingdomBundle\Exception\WrongSlot;
9
10
/**
11
 * Предмет в инвентаре персонажа
12
 * @ORM\Table(
13
 *      name="users_items",
14
 *      uniqueConstraints={
15
 *          @ORM\UniqueConstraint(name="inventory_user_item", columns={"user_id", "item_id"}),
16
 *          @ORM\UniqueConstraint(name="inventory_user_slot", columns={"user_id", "slot"})
17
 *      }
18
 * )
19
 * @ORM\Entity(repositoryClass="Rottenwood\KingdomBundle\Entity\Infrastructure\InventoryItemRepository")
20
 */
21
class InventoryItem
22
{
23
24
    /**
25
     * @ORM\Column(name="id", type="integer")
26
     * @ORM\Id
27
     * @ORM\GeneratedValue(strategy="AUTO")
28
     * @var int
29
     */
30
    private $id;
31
32
    /**
33
     * Персонаж
34
     * @ORM\ManyToOne(targetEntity="Rottenwood\KingdomBundle\Entity\Infrastructure\User")
35
     * @ORM\JoinColumn(name="user_id", referencedColumnName="id", nullable=false)
36
     * @var User
37
     */
38
    private $user;
39
40
    /**
41
     * Предмет
42
     * @ORM\ManyToOne(targetEntity="Rottenwood\KingdomBundle\Entity\Infrastructure\Item")
43
     * @ORM\JoinColumn(name="item_id", referencedColumnName="id", nullable=false)
44
     * @var Item
45
     */
46
    private $item;
47
48
    /**
49
     * Количество предметов
50
     * @var int
51
     * @ORM\Column(name="quantity", type="integer")
52
     */
53
    private $quantity;
54
55
    /**
56
     * Слот, в который одет предмет
57
     * @ORM\Column(name="slot", type="string", length=50, nullable=true)
58
     * @var string
59
     */
60
    private $slot;
61
62
    /**
63
     * @param User $user
64
     * @param Item $item
65
     * @param int  $quantity
66
     */
67
    public function __construct(User $user, Item $item, $quantity = 1)
68
    {
69
        $this->user = $user;
70
        $this->item = $item;
71
        $this->quantity = $quantity;
72
    }
73
74
    /**
75
     * @return int
76
     */
77
    public function getId()
78
    {
79
        return $this->id;
80
    }
81
82
    /**
83
     * @return User
84
     */
85
    public function getUser()
86
    {
87
        return $this->user;
88
    }
89
90
    /**
91
     * @return Item
92
     */
93
    public function getItem()
94
    {
95
        return $this->item;
96
    }
97
98
    /**
99
     * @return int
100
     */
101
    public function getQuantity()
102
    {
103
        return $this->quantity;
104
    }
105
106
    /**
107
     * @param int $quantity
108
     */
109
    public function setQuantity($quantity)
110
    {
111
        $this->quantity = $quantity;
112
    }
113
114
    /**
115
     * @return string
116
     */
117
    public function getSlot()
118
    {
119
        return $this->slot;
120
    }
121
122
    /**
123
     * @param string $slot
124
     * @throws WrongSlot
125
     */
126
    public function setSlot($slot)
127
    {
128
        if (in_array($slot, Item::getAllSlotNames())) {
129
            $this->slot = $slot;
130
        } else {
131
            throw new WrongSlot($slot);
132
        }
133
    }
134
135
    /**
136
     * Удаление предмета из слота
137
     */
138
    public function removeSlot()
139
    {
140
        $this->slot = null;
141
    }
142
}
143