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

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