Passed
Push — master ( d46d5f...674e23 )
by Luis
44s queued 12s
created

UseStatements::fullyQualifiedNameFor()   A

Complexity

Conditions 4
Paths 4

Size

Total Lines 11
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Importance

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