Brand   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 91
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 22
dl 0
loc 91
rs 10
c 0
b 0
f 0
wmc 11

9 Methods

Rating   Name   Duplication   Size   Complexity  
A addProduct() 0 5 2
A removeProduct() 0 5 2
A getId() 0 3 1
A __toString() 0 3 1
A setName() 0 3 1
A getName() 0 3 1
A __construct() 0 4 1
A getCode() 0 3 1
A setCode() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Loevgaard\SyliusBrandPlugin\Model;
6
7
class Brand implements BrandInterface
8
{
9
    use ProductsAwareTrait {
10
        ProductsAwareTrait::__construct as private __productsAwareTraitConstruct;
11
    }
12
    use ImagesAwareTrait {
13
        ImagesAwareTrait::__construct as private __imagesAwareTraitConstruct;
14
    }
15
16
    /**
17
     * @var int
18
     */
19
    protected $id;
20
21
    /**
22
     * @var string|null
23
     */
24
    protected $code;
25
26
    /**
27
     * @var string|null
28
     */
29
    protected $name;
30
31
    public function __construct()
32
    {
33
        $this->__imagesAwareTraitConstruct();
34
        $this->__productsAwareTraitConstruct();
35
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40
    public function __toString(): string
41
    {
42
        return (string) $this->getName();
43
    }
44
45
    /**
46
     * {@inheritdoc}
47
     */
48
    public function getId(): ?int
49
    {
50
        return $this->id;
51
    }
52
53
    /**
54
     * @return string
55
     */
56
    public function getCode(): ?string
57
    {
58
        return $this->code;
59
    }
60
61
    /**
62
     * @param string $code
63
     */
64
    public function setCode(?string $code): void
65
    {
66
        $this->code = $code;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72
    public function getName(): ?string
73
    {
74
        return $this->name;
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80
    public function setName(?string $name): void
81
    {
82
        $this->name = $name;
83
    }
84
85
    public function addProduct(ProductInterface $product): void
86
    {
87
        if (!$this->hasProduct($product)) {
88
            $product->setBrand($this);
89
            $this->products->add($product);
90
        }
91
    }
92
93
    public function removeProduct(ProductInterface $product): void
94
    {
95
        if ($this->hasProduct($product)) {
96
            $product->setBrand(null);
97
            $this->products->removeElement($product);
98
        }
99
    }
100
}
101