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
Push — master ( 8619f1...53d2ad )
by Ross
52s queued 13s
created

ValidatedEntityTrait::setValidator()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 2
nc 1
nop 1
dl 0
loc 4
rs 10
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta\Entity\Traits;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\EntityInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\Validation\EntityValidatorInterface;
7
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
8
use Symfony\Component\Validator\Mapping\ClassMetadata as ValidatorClassMetaData;
9
10
/**
11
 * Trait ValidatedEntityTrait
12
 *
13
 * @package EdmondsCommerce\DoctrineStaticMeta\Entity\Traits
14
 *
15
 * Implements ValidatedEntityInterface
16
 */
17
trait ValidatedEntityTrait
18
{
19
    /**
20
     * @var EntityValidatorInterface
21
     */
22
    protected $validator;
23
24
    /**
25
     * Called in the Entity Constructor
26
     *
27
     * @param EntityValidatorInterface $validator
28
     */
29
    public function setValidator(EntityValidatorInterface $validator): void
30
    {
31
        $this->validator = $validator;
32
        $this->validator->setEntity($this);
0 ignored issues
show
Bug introduced by
$this of type EdmondsCommerce\Doctrine...ts\ValidatedEntityTrait is incompatible with the type EdmondsCommerce\Doctrine...erfaces\EntityInterface expected by parameter $entity of EdmondsCommerce\Doctrine...rInterface::setEntity(). ( Ignorable by Annotation )

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

32
        $this->validator->setEntity(/** @scrutinizer ignore-type */ $this);
Loading history...
33
    }
34
35
    /**
36
     * @param ValidatorClassMetaData $metadata
37
     *
38
     * @throws DoctrineStaticMetaException
39
     */
40
    public static function loadValidatorMetaData(ValidatorClassMetaData $metadata): void
41
    {
42
        static::$reflectionClass = $metadata->getReflectionClass();
0 ignored issues
show
Bug Best Practice introduced by
The property reflectionClass does not exist. Although not strictly required by PHP, it is generally a best practice to declare properties explicitly.
Loading history...
43
        static::loadPropertyValidatorMetaData($metadata);
44
    }
45
46
    /**
47
     * @param ValidatorClassMetaData $metadata
48
     *
49
     * @throws DoctrineStaticMetaException
50
     */
51
    protected static function loadPropertyValidatorMetaData(ValidatorClassMetaData $metadata): void
52
    {
53
        $methodName = '__no_method__';
54
        try {
55
            $staticMethods = static::getStaticMethods();
56
            //now loop through and call them
57
            foreach ($staticMethods as $method) {
58
                $methodName = $method->getName();
59
                if ($methodName === EntityInterface::METHOD_PREFIX_GET_PROPERTY_VALIDATOR_META) {
60
                    continue;
61
                }
62
                if (0 === stripos($methodName, EntityInterface::METHOD_PREFIX_GET_PROPERTY_VALIDATOR_META)) {
63
                    static::$methodName($metadata);
64
                }
65
            }
66
        } catch (\Exception $e) {
67
            throw new DoctrineStaticMetaException(
68
                'Exception in '.__METHOD__.'for '
69
                .self::$reflectionClass->getName()."::$methodName\n\n"
70
                .$e->getMessage()
71
            );
72
        }
73
    }
74
75
    /**
76
     * Is the current Entity valid
77
     *
78
     * @return bool
79
     */
80
    public function isValid(): bool
81
    {
82
        return $this->validator->isValid();
83
    }
84
85
    /**
86
     * Validate the current Entity
87
     *
88
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException
89
     */
90
    public function validate(): void
91
    {
92
        $this->validator->validate();
93
    }
94
95
    /**
96
     * Validate a named property in the current Entity
97
     *
98
     * @param string $propertyName
99
     *
100
     * @throws \EdmondsCommerce\DoctrineStaticMeta\Exception\ValidationException
101
     */
102
    public function validateProperty(string $propertyName): void
103
    {
104
        $this->validator->validateProperty($propertyName);
105
    }
106
}
107