Passed
Push — master ( ffdaaa...2bd757 )
by butschster
20:14 queued 13:13
created

EnumAware   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 26
ccs 12
cts 12
cp 1
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getEnums() 0 10 1
A addEnum() 0 3 1
A getEnum() 0 7 1
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Reactor\Traits;
6
7
use Nette\PhpGenerator\ClassLike;
8
use Nette\PhpGenerator\EnumType;
9
use Nette\PhpGenerator\Helpers;
10
use Spiral\Reactor\Aggregator\Enums;
11
use Spiral\Reactor\EnumDeclaration;
12
13
/**
14
 * @internal
15
 */
16
trait EnumAware
17
{
18 4
    public function addEnum(string $name): EnumDeclaration
19
    {
20 4
        return EnumDeclaration::fromElement($this->element->addEnum($name));
21
    }
22
23 2
    public function getEnum(string $name): EnumDeclaration
24
    {
25
        /**
26
         * @psalm-suppress InternalClass
27
         * @psalm-suppress InternalMethod
28
         */
29 2
        return $this->getEnums()->get(Helpers::extractShortName($name));
30
    }
31
32 14
    public function getEnums(): Enums
33
    {
34 14
        $enums = \array_filter(
35 14
            $this->element->getClasses(),
36 14
            static fn (ClassLike $element): bool => $element instanceof EnumType
37 14
        );
38
39 14
        return new Enums(\array_map(
40 14
            static fn (EnumType $enum): EnumDeclaration => EnumDeclaration::fromElement($enum),
41 14
            $enums
42 14
        ));
43
    }
44
}
45