Passed
Push — master ( 674e23...3482e1 )
by Luis
03:39 queued 39s
created

Name::first()   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 0
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
 * 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 198
    public function __construct(string $name)
19
    {
20 198
        Assert::notEmpty(trim($name), 'Definition name cannot be null or empty');
21 197
        $this->parts = explode('\\', trim($name));
22 197
    }
23
24 21
    public function first(): string
25
    {
26 21
        return $this->parts[0];
27
    }
28
29 103
    public function fullName(): string
30
    {
31 103
        return implode('\\', $this->parts);
32
    }
33
34 25
    public function isArray(): bool
35
    {
36 25
        return str_ends_with((string) $this, '[]');
37
    }
38
39 30
    public function removeArraySuffix(): string
40
    {
41 30
        return str_replace(search: '[]', replace: '', subject: $this->fullName());
42
    }
43
44 129
    public function __toString(): string
45
    {
46 129
        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