VendorsTrait::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 0
dl 0
loc 3
rs 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Odiseo\SyliusVendorPlugin\Entity;
6
7
use Doctrine\Common\Collections\ArrayCollection;
8
use Doctrine\Common\Collections\Collection;
9
10
trait VendorsTrait
11
{
12
    /** @var Collection|VendorInterface[] */
13
    protected $vendors;
14
15
    public function __construct()
16
    {
17
        $this->vendors = new ArrayCollection();
18
    }
19
20
    /**
21
     * @return Collection|VendorInterface[]
22
     */
23
    public function getVendors(): Collection
24
    {
25
        return $this->vendors;
26
    }
27
28
    /**
29
     * @param VendorInterface $vendor
30
     * @return bool
31
     */
32
    public function hasVendor(VendorInterface $vendor): bool
33
    {
34
        return $this->vendors->contains($vendor);
35
    }
36
37
    /**
38
     * @param VendorInterface $vendor
39
     */
40
    public function addVendor(VendorInterface $vendor): void
41
    {
42
        if (!$this->hasVendor($vendor)) {
43
            $this->vendors->add($vendor);
44
        }
45
    }
46
47
    /**
48
     * @param VendorInterface $vendor
49
     */
50
    public function removeVendor(VendorInterface $vendor): void
51
    {
52
        if ($this->hasVendor($vendor)) {
53
            $this->vendors->removeElement($vendor);
54
        }
55
    }
56
}
57