VendorsTrait   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A hasVendor() 0 3 1
A addVendor() 0 4 2
A __construct() 0 3 1
A getVendors() 0 3 1
A removeVendor() 0 4 2
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