Completed
Pull Request — master (#77)
by Mikołaj
01:15
created

SectionableTrait::hasSection()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 4
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 1
1
<?php
2
3
/**
4
 * This file was created by the developers from BitBag.
5
 * Feel free to contact us once you face any issues or want to start
6
 * another great project.
7
 * You can find more information about us on https://bitbag.shop and write us
8
 * an email on [email protected].
9
 */
10
11
declare(strict_types=1);
12
13
namespace BitBag\CmsPlugin\Entity;
14
15
use Doctrine\Common\Collections\ArrayCollection;
16
use Doctrine\Common\Collections\Collection;
17
18
/**
19
 * @author Patryk Drapik <[email protected]>
20
 */
21
trait SectionableTrait
22
{
23
    /**
24
     * @var Collection|SectionInterface[]
25
     */
26
    protected $sections;
27
28
    public function initializeSectionsCollection(): void
29
    {
30
        $this->sections = 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...tity\SectionInterface>> of property $sections.

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...
31
    }
32
33
    /**
34
     * @return Collection|SectionInterface[]
35
     */
36
    public function getSections(): ?Collection
37
    {
38
        return $this->sections;
39
    }
40
41
    /**
42
     * @param SectionInterface $section
43
     *
44
     * @return bool
45
     */
46
    public function hasSection(SectionInterface $section): bool
47
    {
48
        return $this->sections->contains($section);
49
    }
50
51
    /**
52
     * @param SectionInterface $section
53
     */
54
    public function addSection(SectionInterface $section): void
55
    {
56
        $this->sections->add($section);
57
    }
58
59
    /**
60
     * @param SectionInterface $section
61
     */
62
    public function removeSection(SectionInterface $section): void
63
    {
64
        if (true === $this->hasSection($section)) {
65
            $this->sections->removeElement($section);
66
        }
67
    }
68
}
69