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

Tag::getSlug()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
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