Name::getId()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
1
<?php
2
/**
3
 * AnimeDb package.
4
 *
5
 * @author    Peter Gribanov <[email protected]>
6
 * @copyright Copyright (c) 2011, Peter Gribanov
7
 * @license   http://opensource.org/licenses/GPL-3.0 GPL v3
8
 */
9
10
namespace AnimeDb\Bundle\CatalogBundle\Entity;
11
12
use Doctrine\ORM\Mapping as ORM;
13
use Symfony\Component\Validator\Constraints as Assert;
14
15
/**
16
 * Item name.
17
 *
18
 * @ORM\Entity
19
 * @ORM\Table(name="name")
20
 *
21
 * @author  Peter Gribanov <[email protected]>
22
 */
23
class Name
24
{
25
    /**
26
     * @ORM\Id
27
     * @ORM\GeneratedValue
28
     * @ORM\Column(type="integer")
29
     *
30
     * @var int
31
     */
32
    protected $id = 0;
33
34
    /**
35
     * @ORM\Column(type="string", length=256)
36
     * @Assert\NotBlank()
37
     *
38
     * @var string
39
     */
40
    protected $name = '';
41
42
    /**
43
     * @ORM\ManyToOne(targetEntity="Item", inversedBy="names", cascade={"persist"})
44
     * @ORM\JoinColumn(name="item", referencedColumnName="id")
45
     *
46
     * @var Item
47
     */
48
    protected $item;
49
50
    /**
51
     * @return int
52
     */
53 1
    public function getId()
54
    {
55 1
        return $this->id;
56
    }
57
58
    /**
59
     * @param string $name
60
     *
61
     * @return Name
62
     */
63 2
    public function setName($name)
64
    {
65 2
        $this->name = $name;
66
67 2
        return $this;
68
    }
69
70
    /**
71
     * @return string
72
     */
73 2
    public function getName()
74
    {
75 2
        return $this->name;
76
    }
77
78
    /**
79
     * @param Item $item
80
     *
81
     * @return Name
82
     */
83 1
    public function setItem(Item $item = null)
84
    {
85 1
        if ($this->item !== $item) {
86
            // romove link on this item for old item
87 1
            if ($this->item instanceof Item) {
88 1
                $tmp = $this->item;
89 1
                $this->item = null;
90 1
                $tmp->removeName($this);
91 1
            }
92 1
            $this->item = $item;
93
            // add link on this item
94 1
            if ($item instanceof Item) {
95 1
                $this->item->addName($this);
96 1
            }
97 1
        }
98
99 1
        return $this;
100
    }
101
102
    /**
103
     * @return Item
104
     */
105 1
    public function getItem()
106
    {
107 1
        return $this->item;
108
    }
109
110
    /**
111
     * @return string
112
     */
113 1
    public function __toString()
114
    {
115 1
        return $this->getName();
116
    }
117
}
118