Label::addItem()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 9
Ratio 100 %

Code Coverage

Tests 6
CRAP Score 2

Importance

Changes 0
Metric Value
dl 9
loc 9
ccs 6
cts 6
cp 1
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
crap 2
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
use Doctrine\Common\Collections\ArrayCollection;
15
16
/**
17
 * Label.
18
 *
19
 * @ORM\Entity
20
 * @ORM\Table(name="label")
21
 * @ORM\Entity(repositoryClass="AnimeDb\Bundle\CatalogBundle\Repository\Label")
22
 *
23
 * @author  Peter Gribanov <[email protected]>
24
 */
25 View Code Duplication
class Label
0 ignored issues
show
Duplication introduced by
This class seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
26
{
27
    /**
28
     * @ORM\Id
29
     * @ORM\GeneratedValue
30
     * @ORM\Column(type="integer")
31
     *
32
     * @var int
33
     */
34
    protected $id = 0;
35
36
    /**
37
     * @ORM\Column(type="string", length=16)
38
     * @Assert\NotBlank()
39
     *
40
     * @var string
41
     */
42
    protected $name = '';
43
44
    /**
45
     * @ORM\ManyToMany(targetEntity="Item", mappedBy="labels")
46
     *
47
     * @var ArrayCollection
48
     */
49
    protected $items;
50
51 86
    public function __construct()
52
    {
53 86
        $this->items = new ArrayCollection();
54 86
    }
55
56
    /**
57
     * @return int
58
     */
59 1
    public function getId()
60
    {
61 1
        return $this->id;
62
    }
63
64
    /**
65
     * @param string $name
66
     *
67
     * @return Label
68
     */
69 2
    public function setName($name)
70
    {
71 2
        $this->name = $name;
72
73 2
        return $this;
74
    }
75
76
    /**
77
     * @return string
78
     */
79 2
    public function getName()
80
    {
81 2
        return $this->name;
82
    }
83
84
    /**
85
     * @param Item $item
86
     *
87
     * @return Label
88
     */
89 1
    public function addItem(Item $item)
90
    {
91 1
        if (!$this->items->contains($item)) {
92 1
            $this->items->add($item);
93 1
            $item->addLabel($this);
94 1
        }
95
96 1
        return $this;
97
    }
98
99
    /**
100
     * @param Item $item
101
     *
102
     * @return Label
103
     */
104 1
    public function removeItem(Item $item)
105
    {
106 1
        if ($this->items->contains($item)) {
107 1
            $this->items->removeElement($item);
108 1
            $item->removeLabel($this);
109 1
        }
110
111 1
        return $this;
112
    }
113
114
    /**
115
     * @return ArrayCollection
116
     */
117 1
    public function getItems()
118
    {
119 1
        return $this->items;
120
    }
121
122
    /**
123
     * @return string
124
     */
125 1
    public function __toString()
126
    {
127 1
        return $this->getName();
128
    }
129
}
130