Passed
Pull Request — master (#23)
by
unknown
13:36 queued 10:51
created

UseStatement::includes()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
c 0
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 UseStatement
9
{
10 42
    public function __construct(private readonly Name $name, private readonly ?Name $alias)
11
    {
12
    }
13
14 31
    public function endsWith(Name $name): bool
15
    {
16 31
        return str_ends_with(haystack: (string) $this->name, needle: $name->removeArraySuffix());
17
    }
18
19 24
    public function includes(Name $name): bool
20
    {
21 24
        return str_ends_with(haystack: (string) $this->name, needle: $name->first());
22
    }
23
24 24
    public function isAliasedAs(Name $name): bool
25
    {
26 24
        return $this->alias !== null && (string) $this->alias === $name->removeArraySuffix();
27
    }
28
29 28
    public function fullyQualifiedName(Name $name): string
30
    {
31 28
        return $name->isArray() ? "{$this->name->fullName()}[]" : $this->name->fullName();
32
    }
33
34 2
    public function merge(Name $name): string
35
    {
36 2
        return "{$this->name->packageName()}\\{$name->fullName()}";
37
    }
38
}
39