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

StaticReferenceResolver::resolve()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 4

Importance

Changes 0
Metric Value
eloc 7
dl 0
loc 15
ccs 8
cts 8
cp 1
rs 10
c 0
b 0
f 0
cc 4
nc 4
nop 2
crap 4
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Doctrine\Annotations\Parser\Reference;
6
7
use Doctrine\Annotations\Parser\Ast\Reference;
8
use Doctrine\Annotations\Parser\Reference\Exception\ReferenceNotResolvable;
9
use Doctrine\Annotations\Parser\Scope;
10
11
final class StaticReferenceResolver implements ReferenceResolver
12
{
13 10
    public function resolve(Reference $reference, Scope $scope) : string
14
    {
15 10
        if ($reference->isFullyQualified()) {
16 2
            if (! $scope->getImports()->isKnown($reference->getIdentifier())) {
17 1
                throw ReferenceNotResolvable::unknownImport($reference);
18
            }
19
20 1
            return $reference->getIdentifier();
21
        }
22
23 8
        if (! isset($scope->getImports()[$reference->getIdentifier()])) {
24 6
            throw ReferenceNotResolvable::unknownAlias($reference);
25
        }
26
27 7
        return $scope->getImports()[$reference->getIdentifier()];
28
    }
29
}
30