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

CommandCoreFactory::make()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 15
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 2

Importance

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