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

UseStatement   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 29
rs 10
wmc 8

6 Methods

Rating   Name   Duplication   Size   Complexity  
A isAliasedAs() 0 3 2
A merge() 0 3 1
A endsWith() 0 3 1
A includes() 0 3 1
A __construct() 0 2 1
A fullyQualifiedName() 0 3 2
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
    public function __construct(private readonly Name $name, private readonly ?Name $alias)
11
    {
12
    }
13
14
    public function endsWith(Name $name): bool
15
    {
16
        return str_ends_with(haystack: (string) $this->name, needle: $name->removeArraySuffix());
17
    }
18
19
    public function includes(Name $name): bool
20
    {
21
        return str_ends_with(haystack: (string) $this->name, needle: $name->first());
22
    }
23
24
    public function isAliasedAs(Name $name): bool
25
    {
26
        return $this->alias !== null && (string) $this->alias === $name->removeArraySuffix();
27
    }
28
29
    public function fullyQualifiedName(Name $name): string
30
    {
31
        return $name->isArray() ? "{$this->name->fullName()}[]" : $this->name->fullName();
32
    }
33
34
    public function merge(Name $name): string
35
    {
36
        return "{$this->name->packageName()}\\{$name->fullName()}";
37
    }
38
}
39