Passed
Push — enums ( eed0fd )
by Luis
25:29
created

UseStatements::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 0
nc 1
nop 1
dl 0
loc 2
rs 10
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
    public function __construct(private readonly array $useStatements)
12
    {
13
    }
14
15
    public function fullyQualifiedNameFor(Name $name): string
16
    {
17
        foreach ($this->useStatements as $useStatement) {
18
            if ($useStatement->endsWith($name)) {
19
                return $useStatement->fullyQualifiedName($name);
20
            }
21
            if ($useStatement->includes($name)) {
22
                return $useStatement->merge($name);
23
            }
24
            if ($useStatement->isAliasedAs($name)) {
25
                return $useStatement->fullyQualifiedName($name);
26
            }
27
        }
28
        return $name->fullName();
29
    }
30
}
31