Completed
Pull Request — master (#304)
by Piotr
07:03
created

Tag   A

Complexity

Total Complexity 11

Size/Duplication

Total Lines 114
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

Changes 0
Metric Value
wmc 11
lcom 1
cbo 2
dl 0
loc 114
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace FSi\FixturesBundle\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\ORM\Mapping as ORM;
7
use Symfony\Component\Validator\Constraints as Assert;
8
9
/**
10
 * @ORM\Entity
11
 * @ORM\Table(name="tag")
12
 */
13
class Tag
14
{
15
    /**
16
     * @var int
17
     *
18
     * @ORM\Column(type="integer")
19
     * @ORM\Id
20
     * @ORM\GeneratedValue(strategy="AUTO")
21
     */
22
    protected $id;
23
24
    /**
25
     * @var string
26
     *
27
     * @Assert\NotBlank
28
     * @ORM\Column(type="string", length=255)
29
     */
30
    protected $name;
31
32
    /**
33
     * @var News
34
     *
35
     * @ORM\ManyToOne(targetEntity="News", inversedBy="tags")
36
     */
37
    protected $news;
38
39
    /**
40
     * @var ArrayCollection|TagElement[]
41
     *
42
     * @ORM\OneToMany(targetEntity="TagElement", mappedBy="tag", cascade={"persist"}, orphanRemoval=true)
43
     */
44
    protected $elements;
45
46
    public function __construct()
47
    {
48
        $this->elements = new ArrayCollection();
49
    }
50
51
    /**
52
     * @return int
53
     */
54
    public function getId()
55
    {
56
        return $this->id;
57
    }
58
59
    /**
60
     * @param int $id
61
     */
62
    public function setId($id)
63
    {
64
        $this->id = $id;
65
    }
66
67
    /**
68
     * @return string
69
     */
70
    public function getName()
71
    {
72
        return $this->name;
73
    }
74
75
    /**
76
     * @param string $name
77
     */
78
    public function setName($name)
79
    {
80
        $this->name = $name;
81
    }
82
83
    /**
84
     * @return News
85
     */
86
    public function getNews()
87
    {
88
        return $this->news;
89
    }
90
91
    /**
92
     * @param News $news
93
     */
94
    public function setNews(News $news = null)
95
    {
96
        $this->news = $news;
97
    }
98
99
    /**
100
     * @return TagElement[]|ArrayCollection
101
     */
102
    public function getElements()
103
    {
104
        return $this->elements;
105
    }
106
107
    /**
108
     * @param TagElement $element
109
     */
110
    public function addElement(TagElement $element)
111
    {
112
        if (!$this->elements->contains($element)) {
113
            $element->setTag($this);
114
            $this->elements->add($element);
115
        }
116
    }
117
118
    /**
119
     * @param TagElement $element
120
     */
121
    public function removeElement(TagElement $element)
122
    {
123
        $element->setNews(null);
124
        $this->elements->removeElement($element);
125
    }
126
}
127