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

UseStatements   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 18
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 7
dl 0
loc 18
rs 10
c 1
b 0
f 0
wmc 5

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fullyQualifiedNameFor() 0 11 4
A __construct() 0 2 1
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