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

TargetValidator::validate()   B

Complexity

Conditions 10
Paths 7

Size

Total Lines 28
Code Lines 14

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 15
CRAP Score 10

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 28
ccs 15
cts 15
cp 1
rs 7.6666
c 0
b 0
f 0
cc 10
nc 7
nop 2
crap 10

How to fix   Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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