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

InterfaceAware::getInterface()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 7
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 7
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
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\InterfaceType;
10
use Spiral\Reactor\Aggregator\Interfaces;
11
use Spiral\Reactor\InterfaceDeclaration;
12
13
/**
14
 * @internal
15
 */
16
trait InterfaceAware
17
{
18 4
    public function addInterface(string $name): InterfaceDeclaration
19
    {
20 4
        return InterfaceDeclaration::fromElement($this->element->addInterface($name));
21
    }
22
23 2
    public function getInterface(string $name): InterfaceDeclaration
24
    {
25
        /**
26
         * @psalm-suppress InternalClass
27
         * @psalm-suppress InternalMethod
28
         */
29 2
        return $this->getInterfaces()->get(Helpers::extractShortName($name));
30
    }
31
32 14
    public function getInterfaces(): Interfaces
33
    {
34 14
        $interfaces = \array_filter(
35 14
            $this->element->getClasses(),
36 14
            static fn (ClassLike $element): bool => $element instanceof InterfaceType
37 14
        );
38
39 14
        return new Interfaces(\array_map(
40 14
            static fn (InterfaceType $interface): InterfaceDeclaration => InterfaceDeclaration::fromElement($interface),
41 14
            $interfaces
42 14
        ));
43
    }
44
}
45