Passed
Push — 81 ( 07c7b3 )
by Luis
25:00
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
 * PHP version 8.1
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 readonly array $useStatements)
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ARRAY, expecting T_VARIABLE on line 13 at column 49
Loading history...
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->includes($name)) {
24
                return $useStatement->merge($name);
25
            }
26
            if ($useStatement->isAliasedAs($name)) {
27
                return $useStatement->fullyQualifiedName($name);
28
            }
29
        }
30
        return $name->fullName();
31
    }
32
}
33