TaxonAwareTrait::addTaxon()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 4
rs 10
cc 2
nc 2
nop 1
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