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

getPropertyValidatorMetaForTemplateEntities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 3
nc 1
nop 1
dl 0
loc 5
rs 9.4285
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
// phpcs:disable
3
namespace TemplateNamespace\Entity\Relations\TemplateEntity\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 TemplateNamespace\Entities\TemplateEntity as TemplateEntity;
11
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\HasTemplateEntitiesInterface;
12
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\ReciprocatesTemplateEntityInterface;
13
14
/**
15
 * Trait HasTemplateEntitiesAbstract
16
 *
17
 * The base trait for relations to multiple TemplateEntities
18
 *
19
 * @package TemplateNamespace\Entity\Relations\TemplateEntity\Traits
20
 */
21
// phpcs:enable
22
trait HasTemplateEntitiesAbstract
23
{
24
    /**
25
     * @var ArrayCollection|TemplateEntity[]
26
     */
27
    private $templateEntities;
28
29
    /**
30
     * @param ValidatorClassMetaData $metadata
31
     *
32
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
33
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
34
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
35
     */
36
    public static function validatorMetaForTemplateEntities(
37
        ValidatorClassMetaData $metadata
38
    ): void {
39
        $metadata->addPropertyConstraint(
40
            HasTemplateEntitiesInterface::PROPERTY_NAME_TEMPLATE_ENTITIES,
41
            new Valid()
42
        );
43
    }
44
45
    /**
46
     * @param ClassMetadataBuilder $manyToManyBuilder
47
     *
48
     * @return void
49
     */
50
    abstract public static function metaForTemplateEntities(
51
        ClassMetadataBuilder $manyToManyBuilder
52
    ): void;
53
54
    /**
55
     * @return Collection|TemplateEntity[]
56
     */
57
    public function getTemplateEntities(): Collection
58
    {
59
        return $this->templateEntities;
60
    }
61
62
    /**
63
     * @param Collection|TemplateEntity[] $templateEntities
64
     *
65
     * @return self
66
     */
67
    public function setTemplateEntities(
68
        Collection $templateEntities
69
    ): HasTemplateEntitiesInterface {
70
        $this->templateEntities = $templateEntities;
0 ignored issues
show
Documentation Bug introduced by
$templateEntities is of type Doctrine\Common\Collections\Collection, but the property $templateEntities was declared to be of type TemplateNamespace\Entiti...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...
71
72
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type TemplateNamespace\Entity...emplateEntitiesAbstract which is incompatible with the type-hinted return TemplateNamespace\Entity...mplateEntitiesInterface.
Loading history...
73
    }
74
75
    /**
76
     * @param TemplateEntity|null $templateEntity
77
     * @param bool                $recip
78
     *
79
     * @return self
80
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
81
     */
82
    public function addTemplateEntity(
83
        ?TemplateEntity $templateEntity,
84
        bool $recip = true
85
    ): HasTemplateEntitiesInterface {
86
        if ($templateEntity === null) {
87
            return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type TemplateNamespace\Entity...emplateEntitiesAbstract which is incompatible with the type-hinted return TemplateNamespace\Entity...mplateEntitiesInterface.
Loading history...
88
        }
89
90
        if (!$this->templateEntities->contains($templateEntity)) {
91
            $this->templateEntities->add($templateEntity);
92
            if ($this instanceof ReciprocatesTemplateEntityInterface && true === $recip) {
93
                $this->reciprocateRelationOnTemplateEntity($templateEntity);
94
            }
95
        }
96
97
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type TemplateNamespace\Entity...TemplateEntityInterface which is incompatible with the type-hinted return TemplateNamespace\Entity...mplateEntitiesInterface.
Loading history...
98
    }
99
100
    /**
101
     * @param TemplateEntity $templateEntity
102
     * @param bool           $recip
103
     *
104
     * @return self
105
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
106
     */
107
    public function removeTemplateEntity(
108
        TemplateEntity $templateEntity,
109
        bool $recip = true
110
    ): HasTemplateEntitiesInterface {
111
        $this->templateEntities->removeElement($templateEntity);
112
        if ($this instanceof ReciprocatesTemplateEntityInterface && true === $recip) {
113
            $this->removeRelationOnTemplateEntity($templateEntity);
114
        }
115
116
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type TemplateNamespace\Entity...TemplateEntityInterface which is incompatible with the type-hinted return TemplateNamespace\Entity...mplateEntitiesInterface.
Loading history...
117
    }
118
119
    /**
120
     * Initialise the templateEntities property as a Doctrine ArrayCollection
121
     *
122
     * @return $this
123
     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
124
     */
125
    private function initTemplateEntities()
126
    {
127
        $this->templateEntities = new ArrayCollection();
128
129
        return $this;
130
    }
131
}
132