Passed
Branch feature/tags (cc2dab)
by Stone
06:13
created

Tag   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 21
dl 0
loc 88
rs 10
c 0
b 0
f 0

10 Methods

Rating   Name   Duplication   Size   Complexity  
A getTrick() 0 3 1
A setSlug() 0 5 1
A getName() 0 3 1
A __toString() 0 3 1
A setName() 0 5 1
A getSlug() 0 3 1
A getId() 0 3 1
A removeTrick() 0 7 2
A __construct() 0 3 1
A addTrick() 0 7 2
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
    public function addTrick(Trick $trick): self
83
    {
84
        if (!$this->trick->contains($trick)) {
85
            $this->trick[] = $trick;
86
        }
87
88
        return $this;
89
    }
90
91
    public function removeTrick(Trick $trick): self
92
    {
93
        if ($this->trick->contains($trick)) {
94
            $this->trick->removeElement($trick);
95
        }
96
97
        return $this;
98
    }
99
100
    public function __toString()
101
    {
102
        return $this->name;
103
    }
104
}
105