Completed
Pull Request — master (#142)
by
unknown
07:20
created

ChannelsAwareTrait   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 7
lcom 1
cbo 0
dl 0
loc 34
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A initializeChannelsCollection() 0 4 1
A getChannels() 0 4 1
A addChannel() 0 6 2
A removeChannel() 0 6 2
A hasChannel() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * This file has been created by developers from BitBag.
7
 * Feel free to contact us once you face any issues or want to start
8
 * another great project.
9
 * You can find more information about us on https://bitbag.shop and write us
10
 * an email on [email protected].
11
 */
12
13
namespace BitBag\SyliusCmsPlugin\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
use Sylius\Component\Channel\Model\ChannelInterface;
18
19
trait ChannelsAwareTrait
20
{
21
    /** @var Collection|ChannelInterface[] */
22
    protected $channels;
23
24
    public function initializeChannelsCollection(): void
25
    {
26
        $this->channels = new ArrayCollection();
0 ignored issues
show
Documentation Bug introduced by
It seems like new \Doctrine\Common\Collections\ArrayCollection() of type object<Doctrine\Common\C...ctions\ArrayCollection> is incompatible with the declared type object<Doctrine\Common\C...odel\ChannelInterface>> of property $channels.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
27
    }
28
29
    public function getChannels(): Collection
30
    {
31
        return $this->channels;
32
    }
33
34
    public function addChannel(ChannelInterface $channel): void
35
    {
36
        if (!$this->hasChannel($channel)) {
37
            $this->channels->add($channel);
38
        }
39
    }
40
41
    public function removeChannel(ChannelInterface $channel): void
42
    {
43
        if ($this->hasChannel($channel)) {
44
            $this->channels->removeElement($channel);
45
        }
46
    }
47
48
    public function hasChannel(ChannelInterface $channel): bool
49
    {
50
        return $this->channels->contains($channel);
51
    }
52
}
53