GeneratingEnum   A
last analyzed

Complexity

Total Complexity 1

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 1
eloc 10
c 1
b 0
f 0
dl 0
loc 42
ccs 5
cts 5
cp 1
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 9 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\Enum\Data;
6
7
use function Cerbero\Enum\backingType;
8
use function Cerbero\Enum\namespaceToPath;
9
use function Cerbero\Enum\splitNamespace;
10
11
/**
12
 * The enum being generated.
13
 */
14
class GeneratingEnum
15
{
16
    /**
17
     * The namespace of the enum.
18
     */
19
    public readonly string $namespace;
20
21
    /**
22
     * The name of the enum.
23
     */
24
    public readonly string $name;
25
26
    /**
27
     * The absolute path of the enum.
28
     */
29
    public readonly string $path;
30
31
    /**
32
     * Whether the enum exists.
33
     */
34
    public readonly bool $exists;
35
36
    /**
37
     * The backing type, if backed.
38
     */
39
    public readonly ?string $backingType;
40
41
    /**
42
     * Instantiate the class.
43
     *
44
     * @param class-string<\UnitEnum> $fullNamespace
0 ignored issues
show
Documentation Bug introduced by
The doc comment class-string<\UnitEnum> at position 0 could not be parsed: Unknown type name 'class-string' at position 0 in class-string<\UnitEnum>.
Loading history...
45
     * @param array<string, string|int|null> $cases
46
     */
47 4
    public function __construct(public readonly string $fullNamespace, public readonly array $cases)
48
    {
49 4
        [$this->namespace, $this->name] = splitNamespace($fullNamespace);
0 ignored issues
show
Bug introduced by
The property namespace is declared read-only in Cerbero\Enum\Data\GeneratingEnum.
Loading history...
Bug introduced by
The property name is declared read-only in Cerbero\Enum\Data\GeneratingEnum.
Loading history...
50
51 4
        $this->path = namespaceToPath($fullNamespace);
0 ignored issues
show
Bug introduced by
The property path is declared read-only in Cerbero\Enum\Data\GeneratingEnum.
Loading history...
52
53 4
        $this->exists = enum_exists($fullNamespace);
0 ignored issues
show
Bug introduced by
The property exists is declared read-only in Cerbero\Enum\Data\GeneratingEnum.
Loading history...
Bug introduced by
The function enum_exists was not found. Maybe you did not declare it correctly or list all dependencies? ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-call  annotation

53
        $this->exists = /** @scrutinizer ignore-call */ enum_exists($fullNamespace);
Loading history...
54
55 4
        $this->backingType = backingType(reset($cases));
0 ignored issues
show
Bug introduced by
The property backingType is declared read-only in Cerbero\Enum\Data\GeneratingEnum.
Loading history...
56
    }
57
}
58