Test Failed
Pull Request — master (#1111)
by Aleksei
10:51
created

CompatiblePipelineBuilder   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 2
Bugs 1 Features 1
Metric Value
wmc 6
eloc 11
c 2
b 1
f 1
dl 0
loc 30
rs 10

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A withInterceptors() 0 8 2
A __clone() 0 3 1
A build() 0 6 2
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Spiral\Core;
6
7
use Psr\EventDispatcher\EventDispatcherInterface;
8
use Spiral\Interceptors\HandlerInterface;
9
use Spiral\Interceptors\InterceptorInterface;
10
use Spiral\Interceptors\PipelineBuilderInterface;
11
12
/**
13
 * Accepts {@see InterceptorInterface} and {@see CoreInterface} instances to build a pipeline.
14
 *
15
 * @deprecated Use {@see PipelineBuilder} instead.
16
 */
17
class CompatiblePipelineBuilder implements PipelineBuilderInterface
18
{
19
    private InterceptorPipeline $pipeline;
20
21
    public function __construct(?EventDispatcherInterface $dispatcher = null)
22
    {
23
        $this->pipeline = new InterceptorPipeline($dispatcher);
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

23
        $this->pipeline = /** @scrutinizer ignore-deprecated */ new InterceptorPipeline($dispatcher);
Loading history...
24
    }
25
26
    public function __clone()
27
    {
28
        $this->pipeline = clone $this->pipeline;
29
    }
30
31
    public function withInterceptors(CoreInterceptorInterface|InterceptorInterface ...$interceptors): static
32
    {
33
        $clone = clone $this;
34
        foreach ($interceptors as $interceptor) {
35
            $clone->pipeline->addInterceptor($interceptor);
36
        }
37
38
        return $clone;
39
    }
40
41
    public function build(HandlerInterface|CoreInterface $last): InterceptorPipeline
42
    {
43
        /** @psalm-suppress InvalidArgument */
44
        return $last instanceof HandlerInterface
45
            ? $this->pipeline->withHandler($last)
46
            : $this->pipeline->withCore($last);
47
    }
48
}
49