Passed
Pull Request — master (#1104)
by Maxim
12:14
created

CommandCoreFactory   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A make() 0 15 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Console;
6
7
use Psr\Container\ContainerInterface;
8
use Psr\EventDispatcher\EventDispatcherInterface;
9
use Spiral\Console\Interceptor\AttributeInterceptor;
10
use Spiral\Core\Attribute\Scope;
11
use Spiral\Core\CoreInterceptorInterface;
12
use Spiral\Core\CoreInterface;
13
use Spiral\Core\InterceptorPipeline;
14
use Spiral\Interceptors\HandlerInterface;
15
use Spiral\Interceptors\InterceptorInterface;
16
17
#[Scope('console.command')]
18
final class CommandCoreFactory
19
{
20 98
    public function __construct(
21
        private readonly ContainerInterface $container,
22
    ) {
23 98
    }
24
25
    /**
26
     * @param array<class-string<CoreInterceptorInterface|InterceptorInterface>> $interceptors
0 ignored issues
show
Documentation Bug introduced by
The doc comment array<class-string<CoreI...|InterceptorInterface>> at position 2 could not be parsed: Unknown type name 'class-string' at position 2 in array<class-string<CoreInterceptorInterface|InterceptorInterface>>.
Loading history...
27
     */
28 98
    public function make(
29
        array $interceptors,
30
        ?EventDispatcherInterface $eventDispatcher = null,
31
    ): CoreInterface|HandlerInterface {
32
        /** @var CommandCore $core */
33 98
        $core = $this->container->get(CommandCore::class);
34
35 98
        $interceptableCore = (new InterceptorPipeline($eventDispatcher))->withCore($core);
0 ignored issues
show
Deprecated Code introduced by
The class Spiral\Core\InterceptorPipeline has been deprecated: use {@see \Spiral\Interceptors\Handler\InterceptorPipeline} instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

35
        $interceptableCore = (/** @scrutinizer ignore-deprecated */ new InterceptorPipeline($eventDispatcher))->withCore($core);
Loading history...
36
37 98
        foreach ($interceptors as $interceptor) {
38 1
            $interceptableCore->addInterceptor($this->container->get($interceptor));
39
        }
40 98
        $interceptableCore->addInterceptor($this->container->get(AttributeInterceptor::class));
41
42 98
        return $interceptableCore;
43
    }
44
}
45