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

TraitAware::getTraits()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 10
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 8
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 6
c 1
b 0
f 0
dl 0
loc 10
ccs 8
cts 8
cp 1
rs 10
cc 1
nc 1
nop 0
crap 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