Passed
Push — master ( 1416ae...b5a8b1 )
by Luis
54s queued 13s
created

Name   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 11
dl 0
loc 40
ccs 17
cts 17
cp 1
rs 10
c 1
b 0
f 0
wmc 7
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
use Stringable;
11
use Webmozart\Assert\Assert;
12
13
final class Name implements Stringable
14
{
15
    /** @var string[]  */
16
    private readonly array $parts;
0 ignored issues
show
Bug introduced by
A parse error occurred: Syntax error, unexpected T_ARRAY, expecting T_VARIABLE on line 16 at column 21
Loading history...
17
18 211
    public function __construct(string $name)
19
    {
20 211
        Assert::notEmpty(trim($name), 'Definition name cannot be null or empty');
21 210
        $this->parts = explode('\\', trim($name));
22
    }
23
24 24
    public function first(): string
25
    {
26 24
        return $this->parts[0];
27
    }
28
29 136
    public function fullName(): string
30
    {
31 136
        return implode('\\', $this->parts);
32
    }
33
34 28
    public function isArray(): bool
35
    {
36 28
        return str_ends_with((string) $this, '[]');
37
    }
38
39 33
    public function removeArraySuffix(): string
40
    {
41 33
        return str_replace(search: '[]', replace: '', subject: $this->fullName());
42
    }
43
44 130
    public function __toString(): string
45
    {
46 130
        return $this->parts[count($this->parts) - 1];
47
    }
48
49 2
    public function packageName(): string
50
    {
51 2
        $package = array_slice($this->parts, 0, -1);
52 2
        return implode('\\', $package);
53
    }
54
}
55