Tag   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 165
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 5

Test Coverage

Coverage 58.62%

Importance

Changes 0
Metric Value
dl 0
loc 165
ccs 17
cts 29
cp 0.5862
rs 10
c 0
b 0
f 0
wmc 11
lcom 2
cbo 5

11 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A unsetTranslations() 0 6 1
A __toString() 0 4 1
A getId() 0 4 1
A setTitle() 0 6 1
A getTitle() 0 4 1
A setSlug() 0 6 1
A getSlug() 0 4 1
A addPost() 0 6 1
A removePost() 0 4 1
A getPosts() 0 4 1
1
<?php
2
3
namespace App\Entity;
4
5
use App\Traits\DeletedByTrait;
6
use Doctrine\ORM\Mapping as ORM;
7
use Gedmo\Mapping\Annotation as Gedmo;
8
use Gedmo\Blameable\Traits\BlameableEntity;
9
use Symfony\Component\Validator\Constraints as Assert;
10
use App\Traits\TimestampableTrait;
11
use JMS\Serializer\Annotation\ExclusionPolicy;
12
use JMS\Serializer\Annotation\Expose;
13
use JMS\Serializer\Annotation\Type;
14
use Sonata\TranslationBundle\Model\Gedmo\TranslatableInterface;
15
use Sonata\TranslationBundle\Model\Gedmo\AbstractPersonalTranslatable;
16
17
/**
18
 * @ORM\Table(name="tags")
19
 * @ORM\Entity
20
 * @Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
21
 * @Gedmo\TranslationEntity(class="App\Entity\Translations\TagTranslation")
22
 * @ExclusionPolicy("all")
23
 */
24
class Tag extends AbstractPersonalTranslatable  implements TranslatableInterface
25
{
26
    use TimestampableTrait, BlameableEntity, DeletedByTrait;
27
28
    /**
29
     * @var integer
30
     *
31
     * @ORM\Column(name="id", type="integer")
32
     * @ORM\Id
33
     * @ORM\GeneratedValue(strategy="AUTO")
34
     * @Type("integer")
35
     * @Expose
36
     */
37
    private $id;
38
39
    /**
40
     * @var string
41
     * @Gedmo\Translatable
42
     * @Assert\NotBlank()
43
     * @ORM\Column(type="string", length=255)
44
     * @Type("string")
45
     * @Expose
46
     */
47
    private $title;
48
49
    /**
50
     * @Gedmo\Slug(fields={"title"})
51
     * @ORM\Column(name="slug", type="string", length=255)
52
     * @Type("string")
53
     * @Expose
54
     */
55
    private $slug;
56
57
    /**
58
     * @ORM\ManyToMany(targetEntity="App\Entity\Post", mappedBy="tags", cascade={"persist"})
59
     *
60
     */
61
    private $posts;
62
63
    /**
64
     * @var ArrayCollection
65
     *
66
     * @ORM\OneToMany(
67
     *     targetEntity="App\Entity\Translations\TagTranslation",
68
     *     mappedBy="object",
69
     *     cascade={"persist", "remove"}
70
     * )
71
     */
72
    protected $translations;
73
74
    /**
75
     * Constructor
76
     */
77 3
    public function __construct()
78
    {
79 3
        parent::__construct();
80 3
        $this->posts = new \Doctrine\Common\Collections\ArrayCollection();
81 3
    }
82
83
    /**
84
     * Unset translations
85
     *
86
     * @return Tag
87
     */
88 4
    public function unsetTranslations()
89
    {
90 4
        $this->translations = null;
91
92 4
        return $this;
93
    }
94
95 3
    public function __toString()
96
    {
97 3
        return $this->getTitle();
98
    }
99
100
    /**
101
     * Get id
102
     *
103
     * @return integer
104
     */
105 2
    public function getId()
106
    {
107 2
        return $this->id;
108
    }
109
110
    /**
111
     * Set title
112
     *
113
     * @param  string $title
114
     * @return Tag
115
     */
116
    public function setTitle($title)
117
    {
118
        $this->title = $title;
119
120
        return $this;
121
    }
122
123
    /**
124
     * Get title
125
     *
126
     * @return string
127
     */
128 11
    public function getTitle()
129
    {
130 11
        return $this->title;
131
    }
132
133
    /**
134
     * Set slug
135
     *
136
     * @param  string $slug
137
     * @return Tag
138
     */
139
    public function setSlug($slug)
140
    {
141
        $this->slug = $slug;
142
143
        return $this;
144
    }
145
146
    /**
147
     * Get slug
148
     *
149
     * @return string
150
     */
151 1
    public function getSlug()
152
    {
153 1
        return $this->slug;
154
    }
155
156
    /**
157
     * Add post
158
     *
159
     * @param  \App\Entity\Post $post
160
     * @return Tag
161
     */
162
    public function addPost(\App\Entity\Post $post)
163
    {
164
        $this->posts[] = $post;
165
166
        return $this;
167
    }
168
169
    /**
170
     * Remove post
171
     *
172
     * @param \App\Entity\Post $post
173
     */
174
    public function removePost(\App\Entity\Post $post)
175
    {
176
        $this->posts->removeElement($post);
177
    }
178
179
    /**
180
     * Get posts
181
     *
182
     * @return \Doctrine\Common\Collections\Collection
183
     */
184 3
    public function getPosts()
185
    {
186 3
        return $this->posts;
187
    }
188
}
189