ChannelsAwareTrait::addChannel()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 2
eloc 2
nc 2
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
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
/*
12
 * This file was created by developers working at BitBag
13
 * Do you need more information about us and what we do? Visit our https://bitbag.io website!
14
 * 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
15
*/
16
17
namespace BitBag\SyliusCmsPlugin\Entity;
18
19
use Doctrine\Common\Collections\ArrayCollection;
20
use Doctrine\Common\Collections\Collection;
21
use Sylius\Component\Channel\Model\ChannelInterface;
22
23
trait ChannelsAwareTrait
24
{
25
    /** @var Collection|ChannelInterface[] */
26
    protected $channels;
27
28
    public function initializeChannelsCollection(): void
29
    {
30
        $this->channels = new ArrayCollection();
31
    }
32
33
    public function getChannels(): Collection
34
    {
35
        return $this->channels;
36
    }
37
38
    public function addChannel(ChannelInterface $channel): void
39
    {
40
        if (!$this->hasChannel($channel)) {
41
            $this->channels->add($channel);
42
        }
43
    }
44
45
    public function removeChannel(ChannelInterface $channel): void
46
    {
47
        if ($this->hasChannel($channel)) {
48
            $this->channels->removeElement($channel);
49
        }
50
    }
51
52
    public function hasChannel(ChannelInterface $channel): bool
53
    {
54
        return $this->channels->contains($channel);
55
    }
56
}
57