TaxonAwareTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 31
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 7
eloc 9
c 1
b 0
f 0
dl 0
loc 31
rs 10

5 Methods

Rating   Name   Duplication   Size   Complexity  
A getTaxons() 0 3 1
A hasTaxon() 0 3 1
A initializeTaxonCollection() 0 3 1
A removeTaxon() 0 4 2
A addTaxon() 0 4 2
1
<?php
2
3
/*
4
 * This file was created by developers working at BitBag
5
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
6
 * We are hiring developers from all over the world. Join us and start your new, exciting adventure and become part of us: https://bitbag.io/career
7
*/
8
9
declare(strict_types=1);
10
11
namespace BitBag\SyliusCmsPlugin\Entity;
12
13
use Doctrine\Common\Collections\ArrayCollection;
14
use Doctrine\Common\Collections\Collection;
15
use Sylius\Component\Core\Model\TaxonInterface;
16
17
trait TaxonAwareTrait
18
{
19
    /** @var Collection|TaxonInterface[] */
20
    protected $taxonomies;
21
22
    public function initializeTaxonCollection(): void
23
    {
24
        $this->taxonomies = new ArrayCollection();
25
    }
26
27
    public function getTaxons(): Collection
28
    {
29
        return $this->taxonomies;
30
    }
31
32
    public function hasTaxon(TaxonInterface $taxon): bool
33
    {
34
        return $this->taxonomies->contains($taxon);
35
    }
36
37
    public function addTaxon(TaxonInterface $taxon): void
38
    {
39
        if (false === $this->hasTaxon($taxon)) {
40
            $this->taxonomies->add($taxon);
41
        }
42
    }
43
44
    public function removeTaxon(TaxonInterface $taxon): void
45
    {
46
        if (true === $this->hasTaxon($taxon)) {
47
            $this->taxonomies->removeElement($taxon);
48
        }
49
    }
50
}
51