GitHub Access Token became invalid

It seems like the GitHub access token used for retrieving details about this repository from GitHub became invalid. This might prevent certain types of inspections from being run (in particular, everything related to pull requests).
Please ask an admin of your repository to re-new the access token on this website.
Passed
Pull Request — master (#47)
by joseph
02:29
created

HasCustomerSegmentsAbstract::addCustomerSegment()   B

Complexity

Conditions 5
Paths 4

Size

Total Lines 16
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 8.8571
c 0
b 0
f 0
cc 5
eloc 7
nc 4
nop 2
1
<?php declare(strict_types=1);
2
3
namespace My\Test\Project\Entity\Relations\Customer\Segment\Traits;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
8
use Symfony\Component\Validator\Constraints\Valid;
9
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
10
use My\Test\Project\Entities\Customer\Segment as CustomerSegment;
11
use My\Test\Project\Entity\Relations\Customer\Segment\Interfaces\HasCustomerSegmentsInterface;
12
use My\Test\Project\Entity\Relations\Customer\Segment\Interfaces\ReciprocatesCustomerSegmentInterface;
13
14
trait HasCustomerSegmentsAbstract
15
{
16
    /**
17
     * @var ArrayCollection|CustomerSegment[]
18
     */
19
    private $customerSegments;
20
21
    /**
22
     * @param ValidatorClassMetaData $metadata
23
     *
24
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
25
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
26
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
27
     */
28
    public static function getPropertyValidatorMetaForCustomerSegments(ValidatorClassMetaData $metadata): void
29
    {
30
        $metadata->addPropertyConstraint(
31
            HasCustomerSegmentsInterface::PROPERTY_NAME_CUSTOMER_SEGMENTS,
32
            new Valid()
33
        );
34
    }
35
36
    /**
37
     * @param ClassMetadataBuilder $manyToManyBuilder
38
     *
39
     * @return void
40
     */
41
    abstract public static function getPropertyDoctrineMetaForCustomerSegments(
42
        ClassMetadataBuilder $manyToManyBuilder
43
    ): void;
44
45
    /**
46
     * @return Collection|CustomerSegment[]
47
     */
48
    public function getCustomerSegments(): Collection
49
    {
50
        return $this->customerSegments;
51
    }
52
53
    /**
54
     * @param Collection|CustomerSegment[] $customerSegments
55
     *
56
     * @return self
57
     */
58
    public function setCustomerSegments(Collection $customerSegments): HasCustomerSegmentsInterface
59
    {
60
        $this->customerSegments = $customerSegments;
0 ignored issues
show
Documentation Bug introduced by
$customerSegments is of type Doctrine\Common\Collections\Collection, but the property $customerSegments was declared to be of type My\Test\Project\Entities...ections\ArrayCollection. Are you sure that you always receive this specific sub-class here, or does it make sense to add an instanceof check?

Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a given class or a super-class is assigned to a property that is type hinted more strictly.

Either this assignment is in error or an instanceof check should be added for that assignment.

class Alien {}

class Dalek extends Alien {}

class Plot
{
    /** @var  Dalek */
    public $villain;
}

$alien = new Alien();
$plot = new Plot();
if ($alien instanceof Dalek) {
    $plot->villain = $alien;
}
Loading history...
61
62
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type My\Test\Project\Entity\R...ustomerSegmentsAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...stomerSegmentsInterface.
Loading history...
63
    }
64
65
    /**
66
     * @param CustomerSegment|null $customerSegment
67
     * @param bool                $recip
68
     *
69
     * @return self
70
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
71
     */
72
    public function addCustomerSegment(
73
        ?CustomerSegment $customerSegment,
74
        bool $recip = true
75
    ): HasCustomerSegmentsInterface {
76
        if ($customerSegment === null) {
77
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type My\Test\Project\Entity\R...ustomerSegmentsAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...stomerSegmentsInterface.
Loading history...
78
        }
79
80
        if (!$this->customerSegments->contains($customerSegment)) {
81
            $this->customerSegments->add($customerSegment);
82
            if ($this instanceof ReciprocatesCustomerSegmentInterface && true === $recip) {
83
                $this->reciprocateRelationOnCustomerSegment($customerSegment);
84
            }
85
        }
86
87
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type My\Test\Project\Entity\R...ustomerSegmentsAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...stomerSegmentsInterface.
Loading history...
88
    }
89
90
    /**
91
     * @param CustomerSegment $customerSegment
92
     * @param bool           $recip
93
     *
94
     * @return self
95
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
96
     */
97
    public function removeCustomerSegment(
98
        CustomerSegment $customerSegment,
99
        bool $recip = true
100
    ): HasCustomerSegmentsInterface {
101
        $this->customerSegments->removeElement($customerSegment);
102
        if ($this instanceof ReciprocatesCustomerSegmentInterface && true === $recip) {
103
            $this->removeRelationOnCustomerSegment($customerSegment);
104
        }
105
106
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type My\Test\Project\Entity\R...ustomerSegmentsAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...stomerSegmentsInterface.
Loading history...
107
    }
108
109
    /**
110
     * Initialise the customerSegments property as a Doctrine ArrayCollection
111
     *
112
     * @return $this
113
     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
114
     */
115
    private function initCustomerSegments()
116
    {
117
        $this->customerSegments = new ArrayCollection();
118
119
        return $this;
120
    }
121
}
122