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

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