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

HasCustomersAbstract::addCustomer()   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\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 as Customer;
11
use My\Test\Project\Entity\Relations\Customer\Interfaces\HasCustomersInterface;
12
use My\Test\Project\Entity\Relations\Customer\Interfaces\ReciprocatesCustomerInterface;
13
14
trait HasCustomersAbstract
15
{
16
    /**
17
     * @var ArrayCollection|Customer[]
18
     */
19
    private $customers;
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 getPropertyValidatorMetaForCustomers(ValidatorClassMetaData $metadata): void
29
    {
30
        $metadata->addPropertyConstraint(
31
            HasCustomersInterface::PROPERTY_NAME_CUSTOMERS,
32
            new Valid()
33
        );
34
    }
35
36
    /**
37
     * @param ClassMetadataBuilder $manyToManyBuilder
38
     *
39
     * @return void
40
     */
41
    abstract public static function getPropertyDoctrineMetaForCustomers(
42
        ClassMetadataBuilder $manyToManyBuilder
43
    ): void;
44
45
    /**
46
     * @return Collection|Customer[]
47
     */
48
    public function getCustomers(): Collection
49
    {
50
        return $this->customers;
51
    }
52
53
    /**
54
     * @param Collection|Customer[] $customers
55
     *
56
     * @return self
57
     */
58
    public function setCustomers(Collection $customers): HasCustomersInterface
59
    {
60
        $this->customers = $customers;
0 ignored issues
show
Documentation Bug introduced by
$customers is of type Doctrine\Common\Collections\Collection, but the property $customers 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...ts\HasCustomersAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...s\HasCustomersInterface.
Loading history...
63
    }
64
65
    /**
66
     * @param Customer|null $customer
67
     * @param bool                $recip
68
     *
69
     * @return self
70
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
71
     */
72
    public function addCustomer(
73
        ?Customer $customer,
74
        bool $recip = true
75
    ): HasCustomersInterface {
76
        if ($customer === 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...ts\HasCustomersAbstract which is incompatible with the type-hinted return My\Test\Project\Entity\R...s\HasCustomersInterface.
Loading history...
78
        }
79
80
        if (!$this->customers->contains($customer)) {
81
            $this->customers->add($customer);
82
            if ($this instanceof ReciprocatesCustomerInterface && true === $recip) {
83
                $this->reciprocateRelationOnCustomer($customer);
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...ocatesCustomerInterface which is incompatible with the type-hinted return My\Test\Project\Entity\R...s\HasCustomersInterface.
Loading history...
88
    }
89
90
    /**
91
     * @param Customer $customer
92
     * @param bool           $recip
93
     *
94
     * @return self
95
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
96
     */
97
    public function removeCustomer(
98
        Customer $customer,
99
        bool $recip = true
100
    ): HasCustomersInterface {
101
        $this->customers->removeElement($customer);
102
        if ($this instanceof ReciprocatesCustomerInterface && true === $recip) {
103
            $this->removeRelationOnCustomer($customer);
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...ocatesCustomerInterface which is incompatible with the type-hinted return My\Test\Project\Entity\R...s\HasCustomersInterface.
Loading history...
107
    }
108
109
    /**
110
     * Initialise the customers property as a Doctrine ArrayCollection
111
     *
112
     * @return $this
113
     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
114
     */
115
    private function initCustomers()
116
    {
117
        $this->customers = new ArrayCollection();
118
119
        return $this;
120
    }
121
}
122