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 (#152)
by joseph
15:36
created

ValidatorStaticMeta::addValidatorMetaData()   A

Complexity

Conditions 4
Paths 9

Size

Total Lines 17
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 20

Importance

Changes 0
Metric Value
cc 4
eloc 12
nc 9
nop 1
dl 0
loc 17
ccs 0
cts 16
cp 0
crap 20
rs 9.8666
c 0
b 0
f 0
1
<?php declare(strict_types=1);
2
3
namespace EdmondsCommerce\DoctrineStaticMeta;
4
5
use EdmondsCommerce\DoctrineStaticMeta\Entity\Interfaces\ValidatedEntityInterface;
6
use EdmondsCommerce\DoctrineStaticMeta\Exception\DoctrineStaticMetaException;
7
use Symfony\Component\Validator\Mapping\ClassMetadata;
8
9
/**
10
 * This class generates and represents the static meta data that is used for validating a specific Entity FQN
11
 */
12
class ValidatorStaticMeta
13
{
14
    /**
15
     * @var DoctrineStaticMeta
16
     */
17
    private $doctrineStaticMeta;
18
19
    public function __construct(DoctrineStaticMeta $doctrineStaticMeta)
20
    {
21
        $this->doctrineStaticMeta = $doctrineStaticMeta;
22
    }
23
24
    public function addValidatorMetaData(ClassMetadata $metadata): void
25
    {
26
        $methodName = '__no_method__';
27
        try {
28
            $staticMethods = $this->doctrineStaticMeta->getStaticMethods();
29
            //now loop through and call them
30
            foreach ($staticMethods as $method) {
31
                $methodName = $method->getName();
32
                if ($this->methdodNameStartsWithValidatorMetaPrefix($methodName)) {
33
                    $this->callMetaDataMethodOnEntity($method, $metadata);
34
                }
35
            }
36
        } catch (\Exception $e) {
37
            throw new DoctrineStaticMetaException(
38
                'Exception in ' . __METHOD__ . 'for '
39
                . self::class . "::$methodName\n\n"
40
                . $e->getMessage()
41
            );
42
        }
43
    }
44
45
    private function methdodNameStartsWithValidatorMetaPrefix(string $methodName): bool
46
    {
47
        if (0 === \stripos(
48
            $methodName,
49
            ValidatedEntityInterface::METHOD_PREFIX_PROPERTY_VALIDATOR_META
50
        )
51
            ||
52
            0 === \stripos(
53
                $methodName,
54
                ValidatedEntityInterface::METHOD_PREFIX_ENTITY_VALIDATOR_META
55
            )
56
        ) {
57
            return true;
58
        }
59
60
        return false;
61
    }
62
63
    private function callMetaDataMethodOnEntity(\ReflectionMethod $method, ClassMetadata $metadata)
64
    {
65
        $method->setAccessible(true);
66
        $method->invokeArgs(null, [$metadata]);
67
    }
68
}
69