MethodAnnotation::forCase()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 2
c 1
b 0
f 0
dl 0
loc 5
ccs 3
cts 3
cp 1
rs 10
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Cerbero\Enum\Data;
6
7
use Stringable;
8
use UnitEnum;
0 ignored issues
show
Bug introduced by
The type UnitEnum 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...
9
10
/**
11
 * The method annotation.
12
 */
13
class MethodAnnotation implements Stringable
14
{
15
    /**
16
     * Whether the method is static.
17
     */
18
    public readonly bool $isStatic;
19
20
    /**
21
     * Retrieve the method annotation for the given case.
22
     */
23 4
    public static function forCase(UnitEnum $case): static
24
    {
25 4
        $returnType = is_int($case->value ?? null) ? 'int' : 'string';
26
27 4
        return new static($case->name, "static {$returnType} {$case->name}()");
28
    }
29
30
    /**
31
     * Retrieve the method annotation for an instance method.
32
     */
33 4
    public static function instance(string $name, string $returnType): static
34
    {
35 4
        return new static($name, "{$returnType} {$name}()");
36
    }
37
38
    /**
39
     * Instantiate the class.
40
     *
41
     * @param list<class-string> $namespaces
0 ignored issues
show
Bug introduced by
The type Cerbero\Enum\Data\list 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...
42
     */
43 4
    final public function __construct(
44
        public readonly string $name,
45
        public readonly string $annotation,
46
        public readonly array $namespaces = [],
47
    ) {
48 4
        $this->isStatic = str_starts_with($annotation, 'static');
0 ignored issues
show
Bug introduced by
The property isStatic is declared read-only in Cerbero\Enum\Data\MethodAnnotation.
Loading history...
49
    }
50
51
    /**
52
     * Retrieve the method annotation string.
53
     */
54 4
    public function __toString(): string
55
    {
56 4
        return "@method {$this->annotation}";
57
    }
58
}
59