Enum   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 32
Duplicated Lines 0 %

Test Coverage

Coverage 80%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
eloc 10
dl 0
loc 32
ccs 8
cts 10
cp 0.8
rs 10
c 1
b 0
f 1

2 Methods

Rating   Name   Duplication   Size   Complexity  
A value() 0 9 2
A element() 0 9 2
1
<?php
2
3
declare(strict_types = 1);
4
5
namespace DummyGenerator\Core;
6
7
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionInterface;
8
use DummyGenerator\Definitions\Extension\Awareness\RandomizerAwareExtensionTrait;
9
use DummyGenerator\Definitions\Extension\EnumExtensionInterface;
10
use DummyGenerator\Definitions\Extension\Exception\ExtensionArgumentException;
11
use ReflectionEnum;
0 ignored issues
show
Bug introduced by
The type ReflectionEnum 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
use ReflectionException;
13
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...
14
15
class Enum implements EnumExtensionInterface, RandomizerAwareExtensionInterface
16
{
17
    use RandomizerAwareExtensionTrait;
18
19
    /**
20
     * @param class-string<UnitEnum> $enumClassname
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...
21
     * @throws ReflectionException
22
     */
23 2
    public function value(string $enumClassname): string|int
24
    {
25 2
        $enum = new ReflectionEnum($enumClassname);
26
27 2
        if (!$enum->isEnum()) {
28
            throw new ExtensionArgumentException('Argument should be PHP Enum class name');
29
        }
30
31 2
        return $this->randomizer->randomElement($enumClassname::cases())->value;
32
    }
33
34
    /**
35
     * @param class-string<UnitEnum> $enumClassname
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...
36
     * @throws ReflectionException
37
     */
38 1
    public function element(string $enumClassname): UnitEnum
39
    {
40 1
        $enum = new \ReflectionEnum($enumClassname);
41
42 1
        if (!$enum->isEnum()) {
43
            throw new ExtensionArgumentException('Argument should be PHP Enum class name');
44
        }
45
46 1
        return $this->randomizer->randomElement($enumClassname::cases());
47
    }
48
}
49