Passed
Pull Request — 5.0 (#11)
by Luis
11:53 queued 09:06
created

UseStatements::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 2
Code Lines 0

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 1
CRAP Score 1

Importance

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