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

Name   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 29
Duplicated Lines 0 %

Importance

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

5 Methods

Rating   Name   Duplication   Size   Complexity  
A removeArraySuffix() 0 3 1
A __construct() 0 4 1
A fullName() 0 3 1
A __toString() 0 3 1
A isArray() 0 3 1
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