Passed
Push — develop ( 02b19a...b765c6 )
by Stone
04:36
created

Tag   A

Complexity

Total Complexity 13

Size/Duplication

Total Lines 96
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 13
eloc 22
dl 0
loc 96
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getTrick() 0 3 1
A setSlug() 0 5 1
A getName() 0 3 1
A setName() 0 5 1
A getSlug() 0 3 1
A getId() 0 3 1
A __construct() 0 3 1
A __toString() 0 3 1
A removeTrick() 0 7 2
A addTrick() 0 7 2
A getTricks() 0 3 1
1
<?php
2
3
namespace App\Entity;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping as ORM;
8
use Gedmo\Mapping\Annotation as Gedmo;
9
use Symfony\Bridge\Doctrine\Validator\Constraints\UniqueEntity;
10
11
/**
12
 * @ORM\Entity(repositoryClass="App\Repository\TagRepository")
13
 * @UniqueEntity(fields="name", message="this Tag already exists")
14
 */
15
class Tag
16
{
17
    /**
18
     * @ORM\Id()
19
     * @ORM\GeneratedValue()
20
     * @ORM\Column(type="integer")
21
     */
22
    private $id;
23
24
    /**
25
     * @ORM\Column(type="string", length=255, unique=true)
26
     */
27
    private $name;
28
29
    /**
30
     * @ORM\Column(type="string", length=255, unique=true)
31
     * @Gedmo\Slug(fields={"name"})
32
     */
33
    private $slug;
34
35
    /**
36
     * @ORM\ManyToMany(targetEntity="App\Entity\Trick", mappedBy="tags", cascade={"persist"})
37
     */
38
    private $trick;
39
40
    public function __construct()
41
    {
42
        $this->trick = new ArrayCollection();
43
    }
44
45
    public function getId(): ?int
46
    {
47
        return $this->id;
48
    }
49
50
    public function getName(): ?string
51
    {
52
        return $this->name;
53
    }
54
55
    public function setName(string $name): self
56
    {
57
        $this->name = $name;
58
59
        return $this;
60
    }
61
62
    public function getSlug(): ?string
63
    {
64
        return $this->slug;
65
    }
66
67
    public function setSlug(string $slug): self
68
    {
69
        $this->slug = $slug;
70
71
        return $this;
72
    }
73
74
    /**
75
     * @return Collection|Trick[]
76
     */
77
    public function getTrick(): Collection
78
    {
79
        return $this->trick;
80
    }
81
82
    /**
83
     * @return Collection|Trick[]
84
     */
85
    public function getTricks(): Collection
86
    {
87
        return $this->trick;
88
    }
89
90
    public function addTrick(Trick $trick): self
91
    {
92
        if (!$this->trick->contains($trick)) {
93
            $this->trick[] = $trick;
94
        }
95
96
        return $this;
97
    }
98
99
    public function removeTrick(Trick $trick): self
100
    {
101
        if ($this->trick->contains($trick)) {
102
            $this->trick->removeElement($trick);
103
        }
104
105
        return $this;
106
    }
107
108
    public function __toString()
109
    {
110
        return $this->name;
111
    }
112
}
113