AnnotationTarget::annotation()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
eloc 1
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Metadata;
6
7
use Doctrine\Annotations\Annotation\Target;
8
9
final class AnnotationTarget
10
{
11
    public const TARGET_CLASS      = 1;
12
    public const TARGET_METHOD     = 2;
13
    public const TARGET_PROPERTY   = 4;
14
    public const TARGET_ANNOTATION = 8;
15
    public const TARGET_ALL        = self::TARGET_CLASS
16
        | self::TARGET_METHOD
17
        | self::TARGET_PROPERTY
18
        | self::TARGET_ANNOTATION;
19
20
    /** @var int */
21
    private $target;
22
23 10
    public function __construct(int $target)
24
    {
25 10
        $this->target = $target;
26 10
    }
27
28
    public static function fromAnnotation(Target $annotation) : self
29
    {
30
        return new self($annotation->targets);
31
    }
32
33
    public function get() : int
34
    {
35
        return $this->target;
36
    }
37
38
    public function class() : bool
39
    {
40
        return ($this->target & self::TARGET_CLASS) === self::TARGET_CLASS;
41
    }
42
43 3
    public function property() : bool
44
    {
45 3
        return ($this->target & self::TARGET_PROPERTY) === self::TARGET_PROPERTY;
46
    }
47
48 2
    public function method() : bool
49
    {
50 2
        return ($this->target & self::TARGET_METHOD) === self::TARGET_METHOD;
51
    }
52
53 4
    public function annotation() : bool
54
    {
55 4
        return ($this->target & self::TARGET_ANNOTATION) === self::TARGET_ANNOTATION;
56
    }
57
58 26
    public function all() : bool
59
    {
60 26
        return ($this->target & self::TARGET_ALL) === self::TARGET_ALL;
61
    }
62
}
63