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

TraitAware   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 addTrait() 0 3 1
A getTrait() 0 7 1
A getTraits() 0 10 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\Helpers;
9
use Nette\PhpGenerator\TraitType;
10
use Spiral\Reactor\Aggregator\Traits;
11
use Spiral\Reactor\TraitDeclaration;
12
13
/**
14
 * @internal
15
 */
16
trait TraitAware
17
{
18 4
    public function addTrait(string $name): TraitDeclaration
19
    {
20 4
        return TraitDeclaration::fromElement($this->element->addTrait($name));
21
    }
22
23 2
    public function getTrait(string $name): TraitDeclaration
24
    {
25
        /**
26
         * @psalm-suppress InternalClass
27
         * @psalm-suppress InternalMethod
28
         */
29 2
        return $this->getTraits()->get(Helpers::extractShortName($name));
30
    }
31
32 14
    public function getTraits(): Traits
33
    {
34 14
        $traits = \array_filter(
35 14
            $this->element->getClasses(),
36 14
            static fn (ClassLike $element): bool => $element instanceof TraitType
37 14
        );
38
39 14
        return new Traits(\array_map(
40 14
            static fn (TraitType $trait): TraitDeclaration => TraitDeclaration::fromElement($trait),
41 14
            $traits
42 14
        ));
43
    }
44
}
45