BookableTag   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 41
Duplicated Lines 0 %

Test Coverage

Coverage 18.18%

Importance

Changes 0
Metric Value
wmc 5
eloc 14
c 0
b 0
f 0
dl 0
loc 41
ccs 2
cts 11
cp 0.1818
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A addBookable() 0 5 2
A removeBookable() 0 4 1
A getBookables() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Application\Model;
6
7
use Application\Repository\BookableTagRepository;
8
use Application\Traits\HasColor;
9
use Doctrine\Common\Collections\ArrayCollection;
10
use Doctrine\Common\Collections\Collection;
11
use Doctrine\ORM\Mapping as ORM;
12
use Ecodev\Felix\Model\Traits\HasName;
13
14
/**
15
 * A type of bookable.
16
 *
17
 * Typical values would be: "Voilier", "SUP".
18
 */
19
#[ORM\UniqueConstraint(name: 'unique_name', columns: ['name'])]
20
#[ORM\Entity(BookableTagRepository::class)]
21
class BookableTag extends AbstractModel
22
{
23
    use HasColor;
24
    use HasName;
25
26
    /**
27
     * @var Collection<int, Bookable>
28
     */
29
    #[ORM\ManyToMany(targetEntity: Bookable::class, inversedBy: 'bookableTags')]
30
    private Collection $bookables;
31
32 3
    public function __construct()
33
    {
34 3
        $this->bookables = new ArrayCollection();
35
    }
36
37
    public function getBookables(): Collection
38
    {
39
        return $this->bookables;
40
    }
41
42
    /**
43
     * Add bookable.
44
     */
45
    public function addBookable(Bookable $bookable): void
46
    {
47
        if (!$this->bookables->contains($bookable)) {
48
            $this->bookables->add($bookable);
49
            $bookable->bookableTagAdded($this);
50
        }
51
    }
52
53
    /**
54
     * Remove bookable.
55
     */
56
    public function removeBookable(Bookable $bookable): void
57
    {
58
        $this->bookables->removeElement($bookable);
59
        $bookable->bookableTagRemoved($this);
60
    }
61
}
62