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.
Completed
Pull Request — master (#75)
by joseph
14:44
created

validatorMetaForTemplateEntity()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 6
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 1
1
<?php declare(strict_types=1);
2
// phpcs:disable
3
namespace TemplateNamespace\Entity\Relations\TemplateEntity\Traits;
4
5
use Doctrine\ORM\Mapping\Builder\ClassMetadataBuilder;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
7
use Symfony\Component\Validator\Constraints\Valid;
8
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
9
use TemplateNamespace\Entities\TemplateEntity as TemplateEntity;
10
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\HasTemplateEntityInterface;
11
use TemplateNamespace\Entity\Relations\TemplateEntity\Interfaces\ReciprocatesTemplateEntityInterface;
12
13
/**
14
 * Trait HasTemplateEntityAbstract
15
 *
16
 * The base trait for relations to a single TemplateEntity
17
 *
18
 * @package TemplateNamespace\Entity\Relations\TemplateEntity\Traits
19
 */
20
// phpcs:enable
21
trait HasTemplateEntityAbstract
22
{
23
    /**
24
     * @var TemplateEntity|null
25
     */
26
    private $templateEntity;
27
28
    /**
29
     * @param ClassMetadataBuilder $builder
30
     *
31
     * @return void
32
     */
33
    abstract public static function metaForTemplateEntity(
34
        ClassMetadataBuilder $builder
35
    ): void;
36
37
    /**
38
     * @param ValidatorClassMetaData $metadata
39
     *
40
     * @throws \Symfony\Component\Validator\Exception\MissingOptionsException
41
     * @throws \Symfony\Component\Validator\Exception\InvalidOptionsException
42
     * @throws \Symfony\Component\Validator\Exception\ConstraintDefinitionException
43
     */
44
    public static function validatorMetaForTemplateEntity(
45
        ValidatorClassMetaData $metadata
46
    ): void {
47
        $metadata->addPropertyConstraint(
48
            HasTemplateEntityInterface::PROPERTY_NAME_TEMPLATE_ENTITY,
49
            new Valid()
50
        );
51
    }
52
53
    /**
54
     * @return TemplateEntity|null
55
     */
56
    public function getTemplateEntity(): ?TemplateEntity
57
    {
58
        return $this->templateEntity;
59
    }
60
61
    /**
62
     * @param TemplateEntity|null $templateEntity
63
     * @param bool                $recip
64
     *
65
     * @return HasTemplateEntityInterface
66
     * @SuppressWarnings(PHPMD.BooleanArgumentFlag)
67
     */
68
    public function setTemplateEntity(
69
        ?TemplateEntity $templateEntity,
70
        bool $recip = true
71
    ): HasTemplateEntityInterface {
72
73
        $this->setEntityAndNotify('templateEntity', $templateEntity);
0 ignored issues
show
Bug introduced by
It seems like setEntityAndNotify() must be provided by classes using this trait. How about adding it as abstract method to this trait? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

73
        $this->/** @scrutinizer ignore-call */ 
74
               setEntityAndNotify('templateEntity', $templateEntity);
Loading history...
74
        if (
75
            $this instanceof ReciprocatesTemplateEntityInterface
76
            && true === $recip
77
            && null !== $templateEntity
78
        ) {
79
            $this->reciprocateRelationOnTemplateEntity($templateEntity);
80
        }
81
82
        return $this;
0 ignored issues
show
Bug Best Practice introduced by
The expression return $this returns the type TemplateNamespace\Entity...sTemplateEntityAbstract which is incompatible with the type-hinted return TemplateNamespace\Entity...TemplateEntityInterface.
Loading history...
83
    }
84
85
    /**
86
     * @param null|TemplateEntity $templateEntity
87
     * @param bool                $recip
88
     *
89
     * @return HasTemplateEntityInterface
90
     */
91
    public function removeTemplateEntity(
92
        ?TemplateEntity $templateEntity = null,
93
        bool $recip = true
94
    ): HasTemplateEntityInterface {
95
        if (
96
            $this instanceof ReciprocatesTemplateEntityInterface
97
            && true === $recip
98
        ) {
99
            if (!$templateEntity instanceof EntityInterface) {
100
                $templateEntity = $this->getTemplateEntity();
101
            }
102
            $remover = 'remove'.static::getSingular();
0 ignored issues
show
Bug introduced by
The method getSingular() does not exist on TemplateNamespace\Entity...TemplateEntityInterface. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

102
            $remover = 'remove'.static::/** @scrutinizer ignore-call */ getSingular();

This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.

This is most likely a typographical error or the method has been renamed.

Loading history...
103
            $templateEntity->$remover($this, false);
104
        }
105
106
        return $this->setTemplateEntity(null, false);
107
    }
108
}
109