Failed Conditions
Push — new-parser-ast-metadata ( 6127e0...5a4a16 )
by Michael
12s
created

TargetValidator   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
eloc 15
dl 0
loc 33
ccs 15
cts 15
cp 1
rs 10
c 0
b 0
f 0

1 Method

Rating   Name   Duplication   Size   Complexity  
B validate() 0 28 10
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Assembler\Validator;
6
7
use Doctrine\Annotations\Assembler\Validator\Exception\InvalidTarget;
8
use Doctrine\Annotations\Metadata\AnnotationMetadata;
9
use Doctrine\Annotations\Parser\Scope;
10
use ReflectionClass;
11
use ReflectionMethod;
12
use ReflectionProperty;
13
14
final class TargetValidator
15
{
16
    /**
17
     * @throws InvalidTarget
18
     */
19 26
    public function validate(AnnotationMetadata $metadata, Scope $scope) : void
20
    {
21 26
        $target = $metadata->getTarget();
22
23 26
        if ($target->all()) {
24 16
            return;
25
        }
26
27 11
        if ($scope->isNested()) {
28 4
            if (! $target->annotation()) {
29 3
                throw InvalidTarget::annotation($metadata);
30
            }
31
32 1
            return;
33
        }
34
35 7
        $subject = $scope->getSubject();
36
37 7
        if ($subject instanceof ReflectionClass && ! $target->class()) {
38 1
            throw InvalidTarget::class($metadata);
39
        }
40
41 6
        if ($subject instanceof ReflectionProperty && ! $target->property()) {
42 1
            throw InvalidTarget::property($metadata);
43
        }
44
45 5
        if ($subject instanceof ReflectionMethod && ! $target->method()) {
46 1
            throw InvalidTarget::method($metadata);
47
        }
48
49
        // TODO validate annotation target
50 4
    }
51
}
52