Passed
Push — 5.0 ( d46d5f...674e23 )
by Luis
50s queued 12s
created

Name::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 1
dl 0
loc 4
rs 10
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
use Stringable;
11
use Webmozart\Assert\Assert;
0 ignored issues
show
Bug introduced by
The type Webmozart\Assert\Assert was not found. Maybe you did not declare it correctly or list all dependencies?

The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g. excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:

filter:
    dependency_paths: ["lib/*"]

For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths

Loading history...
12
13
final class Name implements Stringable
14
{
15
    /** @var string[]  */
16
    private array $parts;
17
18
    public function __construct(string $name)
19
    {
20
        Assert::notEmpty(trim($name), 'Definition name cannot be null or empty');
21
        $this->parts = explode('\\', trim($name));
22
    }
23
24
    public function fullName(): string
25
    {
26
        return implode('\\', $this->parts);
27
    }
28
29
    public function isArray(): bool
30
    {
31
        return str_ends_with((string) $this, '[]');
32
    }
33
34
    public function removeArraySuffix(): string
35
    {
36
        return str_replace(search: '[]', replace: '', subject: $this->fullName());
37
    }
38
39
    public function __toString(): string
40
    {
41
        return $this->parts[count($this->parts) - 1];
42
    }
43
}
44