Tag::getTaggings()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 1
eloc 2
nc 1
nop 0
1
<?php
2
3
namespace DoS\TaggingBundle\Model;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
8
class Tag implements TagInterface
9
{
10
    /**
11
     * @var int
12
     */
13
    protected $id;
14
15
    /**
16
     * @var string
17
     */
18
    protected $name;
19
20
    /**
21
     * @var Collection|TaggingInterface[]
22
     */
23
    protected $taggings;
24
25
    public function __construct()
26
    {
27
        $this->taggings = new ArrayCollection();
28
    }
29
30
    /**
31
     * {@inheritdoc}
32
     */
33
    public function getId()
34
    {
35
        return $this->id;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41
    public function getName()
42
    {
43
        return $this->name;
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49
    public function setName($name)
50
    {
51
        $this->name = preg_replace('/\s++/', ' ', $name);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function getTaggings()
58
    {
59
        return $this->taggings;
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setTaggings($taggings)
66
    {
67
        if (!$taggings instanceof Collection) {
68
            $taggings = new ArrayCollection($taggings);
69
        }
70
71
        foreach($taggings as $tagging) {
72
            $tagging->setTag($this);
73
        }
74
75
        $this->taggings = $taggings;
76
    }
77
78
    /**
79
     * {@inheritdoc}
80
     */
81
    public function hasTagging(TaggingInterface $tagging)
82
    {
83
        return $this->taggings->contains($tagging);
84
    }
85
86
    /**
87
     * {@inheritdoc}
88
     */
89
    public function addTagging(TaggingInterface $tagging)
90
    {
91
        if (!$this->hasTagging($tagging)) {
92
            $tagging->setTag($this);
93
            $this->taggings->add($tagging);
94
        }
95
    }
96
97
    /**
98
     * {@inheritdoc}
99
     */
100
    public function removeTagging(TaggingInterface $tagging)
101
    {
102
        if ($this->hasTagging($tagging)) {
103
            $tagging->setTag(null);
104
            $this->taggings->removeElement($tagging);
105
        }
106
    }
107
}
108