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 (#43)
by Ross
02:30
created

HasTemplateEntitiesAbstract::getTemplateEntities()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace TemplateNamespace\Entity\Relations\TemplateEntity\Traits;
4
5
use Doctrine\Common\Collections\ArrayCollection;
6
use Doctrine\Common\Collections\Collection;
7
use Doctrine\Common\Inflector\Inflector;
8
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
9
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\UsesPHPMetaDataInterface;
10
use Symfony\Component\Validator\Constraints\Valid;
11
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
12
use TemplateNamespace\Entities\TemplateEntity as TemplateEntity;
13
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\HasTemplateEntitiesInterface;
14
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\ReciprocatesTemplateEntityInterface;
15
16
trait HasTemplateEntitiesAbstract
17
{
18
    /**
19
     * @var ArrayCollection|TemplateEntity[]
20
     */
21
    private $templateEntities;
22
23
    /**
24
     * @param ValidatorClassMetaData $metadata
25
     *
26
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
27
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
28
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
29
     */
30
    public static function getPropertyValidatorMetaForTemplateEntities(ValidatorClassMetaData $metadata): void
31
    {
32
        $metadata->addPropertyConstraint(
33
            HasTemplateEntitiesInterface::PROPERTY_NAME_TEMPLATE_ENTITIES,
34
            new Valid()
35
        );
36
    }
37
38
    /**
39
     * @param ClassMetadataBuilder $manyToManyBuilder
40
     *
41
     * @return void
42
     */
43
    abstract public static function getPropertyDoctrineMetaForTemplateEntities(
44
        ClassMetadataBuilder $manyToManyBuilder
45
    ): void;
46
47
    /**
48
     * @return Collection|TemplateEntity[]
49
     */
50
    public function getTemplateEntities(): Collection
51
    {
52
        return $this->templateEntities;
53
    }
54
55
    /**
56
     * @param Collection|TemplateEntity[] $templateEntities
57
     *
58
     * @return self
59
     */
60
    public function setTemplateEntities(Collection $templateEntities): self
61
    {
62
        $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...
63
64
        return $this;
65
    }
66
67
    /**
68
     * @param TemplateEntity|null $templateEntity
69
     * @param bool                $recip
70
     *
71
     * @return self
72
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
73
     */
74
    public function addTemplateEntity(
75
        ?TemplateEntity $templateEntity,
76
        bool $recip = true
77
    ): self {
78
        if($templateEntity === null) {
79
            return $this;
80
        }
81
82
        if (!$this->templateEntities->contains($templateEntity)) {
83
            $this->templateEntities->add($templateEntity);
84
            if ($this instanceof ReciprocatesTemplateEntityInterface && true === $recip) {
85
                $this->reciprocateRelationOnTemplateEntity($templateEntity);
86
            }
87
        }
88
89
        return $this;
90
    }
91
92
    /**
93
     * @param TemplateEntity $templateEntity
94
     * @param bool           $recip
95
     *
96
     * @return self
97
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
98
     */
99
    public function removeTemplateEntity(
100
        TemplateEntity $templateEntity,
101
        bool $recip = true
102
    ): self {
103
        $this->templateEntities->removeElement($templateEntity);
104
        if ($this instanceof ReciprocatesTemplateEntityInterface && true === $recip) {
105
            $this->removeRelationOnTemplateEntity($templateEntity);
106
        }
107
108
        return $this;
109
    }
110
111
    /**
112
     * Initialise the templateEntities property as a Doctrine ArrayCollection
113
     *
114
     * @return $this
115
     * @SuppressWarnings(PHPMD.UnusedPrivateMethod)
116
     */
117
    private function initTemplateEntities()
118
    {
119
        $this->templateEntities = new ArrayCollection();
120
121
        return $this;
122
    }
123
}
124