Failed Conditions
Push — master ( 47998f...c62f8a )
by Sam
06:13
created

BookableTag::addBookable()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 6

Importance

Changes 0
Metric Value
cc 2
eloc 3
nc 2
nop 1
dl 0
loc 5
ccs 0
cts 4
cp 0
crap 6
rs 10
c 0
b 0
f 0
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Traits\HasColor;
8
use Application\Traits\HasName;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
13
/**
14
 * A type of bookable.
15
 *
16
 * Typical values would be: "Voilier", "SUP".
17
 *
18
 * @ORM\Entity(repositoryClass="Application\Repository\BookableTagRepository")
19
 * @ORM\Table(uniqueConstraints={
20
 *     @ORM\UniqueConstraint(name="unique_name", columns={"name"})
21
 * })
22
 */
23
class BookableTag extends AbstractModel
24
{
25
    use HasName;
26
    use HasColor;
27
28
    /**
29
     * @var Collection
30
     * @ORM\ManyToMany(targetEntity="Bookable", inversedBy="bookableTags")
31
     */
32
    private $bookables;
33
34
    /**
35
     * Constructor
36
     */
37
    public function __construct()
38
    {
39
        $this->bookables = new ArrayCollection();
40
    }
41
42
    /**
43
     * @return Collection
44
     */
45
    public function getBookables(): Collection
46
    {
47
        return $this->bookables;
48
    }
49
50
    /**
51
     * Add bookable
52
     *
53
     * @param bookable $bookable
54
     */
55
    public function addBookable(Bookable $bookable): void
56
    {
57
        if (!$this->bookables->contains($bookable)) {
58
            $this->bookables->add($bookable);
59
            $bookable->bookableTagAdded($this);
60
        }
61
    }
62
63
    /**
64
     * Remove bookable
65
     *
66
     * @param bookable $bookable
67
     */
68
    public function removeBookable(Bookable $bookable): void
69
    {
70
        $this->bookables->removeElement($bookable);
71
        $bookable->bookableTagRemoved($this);
72
    }
73
}
74