Failed Conditions
Pull Request — new-parser-ast-metadata (#2)
by
unknown
02:16
created

Scope::getSubject()   A

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\Parser;
6
7
use ReflectionClass;
8
use ReflectionFunctionAbstract;
9
use ReflectionProperty;
10
use Reflector;
11
12
/**
13
 * Represents the source scope effective at the phpDoc declaration.
14
 *
15
 * @internal
16
 */
17
final class Scope
18
{
19
    /** @var ReflectionClass|ReflectionProperty|ReflectionFunctionAbstract */
20
    private $subject;
21
22
    /** @var Imports */
23
    private $imports;
24
25
    /** @var IgnoredAnnotations */
26
    private $ignoredAnnotations;
27
28
    /** @var int */
29
    private $nestingLevel;
30
31 43
    public function __construct(
32
        Reflector $subject,
33
        Imports $imports,
34
        IgnoredAnnotations $ignoredAnnotations,
35
        int $nestingLevel = 0
36
    )
37
    {
38 43
        assert(
39 43
            $subject instanceof ReflectionClass
40 3
            || $subject instanceof ReflectionProperty
41 43
            || $subject instanceof ReflectionFunctionAbstract
42
        );
43 43
        assert($nestingLevel >= 0);
44
45 43
        $this->subject            = $subject;
46 43
        $this->imports            = $imports;
47 43
        $this->ignoredAnnotations = $ignoredAnnotations;
48 43
        $this->nestingLevel       = $nestingLevel;
49 43
    }
50
51
    /**
52
     * @return ReflectionClass|ReflectionFunctionAbstract|ReflectionProperty
53
     */
54 18
    public function getSubject() : Reflector
55
    {
56 18
        return $this->subject;
57
    }
58
59 23
    public function getImports() : Imports
60
    {
61 23
        return $this->imports;
62
    }
63
64 8
    public function getIgnoredAnnotations() : IgnoredAnnotations
65
    {
66 8
        return $this->ignoredAnnotations;
67
    }
68
69 11
    public function isNested() : bool
70
    {
71 11
        return $this->nestingLevel > 1;
72
    }
73
74 9
    public function increaseNestingLevel() : void
75
    {
76 9
        $this->nestingLevel++;
77 9
    }
78
79 9
    public function decreaseNestingLevel() : void
80
    {
81 9
        assert($this->nestingLevel > 0);
82
83 9
        $this->nestingLevel--;
84 9
    }
85
}
86