Passed
Pull Request — master (#30)
by
unknown
46:28 queued 21:27
created

UseStatements::fullyQualifiedNameFor()   A

Complexity

Conditions 5
Paths 5

Size

Total Lines 14
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 5
eloc 8
nc 5
nop 1
dl 0
loc 14
ccs 9
cts 9
cp 1
crap 5
rs 9.6111
c 1
b 0
f 0
1
<?php declare(strict_types=1);
2
/**
3
 * This source file is subject to the license that is bundled with this package in the file LICENSE.
4
 */
5
6
namespace PhUml\Code;
7
8
final class UseStatements
9
{
10
    /** @param UseStatement[] $useStatements */
11 85
    public function __construct(private readonly array $useStatements)
12
    {
13
    }
14
15 47
    public function fullyQualifiedNameFor(Name $name): string
16
    {
17 47
        foreach ($this->useStatements as $useStatement) {
18 29
            if ($useStatement->endsWith($name)) {
19 25
                return $useStatement->fullyQualifiedName($name);
20
            }
21 24
            if ($useStatement->includes($name)) {
22 2
                return $useStatement->merge($name);
23
            }
24 22
            if ($useStatement->isAliasedAs($name)) {
25 8
                return $useStatement->fullyQualifiedName($name);
26
            }
27
        }
28 35
        return $name->fullName();
29
    }
30
}
31