Tag::__toString()   A
last analyzed

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 extends AbstractAppEntity
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
58
        $this->name = strtolower($name);
59
60
        return $this;
61
    }
62
63
    public function getSlug(): ?string
64
    {
65
        return $this->slug;
66
    }
67
68
    public function setSlug(string $slug): self
69
    {
70
        $this->slug = $slug;
71
72
        return $this;
73
    }
74
75
    /**
76
     * @return Collection|Trick[]
77
     */
78
    public function getTrick(): Collection
79
    {
80
        return $this->trick;
81
    }
82
83
    /**
84
     * @return Collection|Trick[]
85
     */
86
    public function getTricks(): Collection
87
    {
88
        return $this->trick;
89
    }
90
91
    public function addTrick(Trick $trick): self
92
    {
93
        if (!$this->trick->contains($trick)) {
94
            $this->trick[] = $trick;
95
        }
96
97
        return $this;
98
    }
99
100
    public function removeTrick(Trick $trick): self
101
    {
102
        if ($this->trick->contains($trick)) {
103
            $this->trick->removeElement($trick);
104
        }
105
106
        return $this;
107
    }
108
109
    public function __toString()
110
    {
111
        return $this->name;
112
    }
113
}
114