Passed
Pull Request — master (#1111)
by Aleksei
11:44
created

CompatiblePipelineBuilder::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
eloc 1
c 1
b 0
f 1
dl 0
loc 3
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\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 175
    public function __construct(?EventDispatcherInterface $dispatcher = null)
22
    {
23 175
        $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 172
    public function __clone()
27
    {
28 172
        $this->pipeline = clone $this->pipeline;
29
    }
30
31 172
    public function withInterceptors(CoreInterceptorInterface|InterceptorInterface ...$interceptors): static
32
    {
33 172
        $clone = clone $this;
34 172
        foreach ($interceptors as $interceptor) {
35 161
            $clone->pipeline->addInterceptor($interceptor);
36
        }
37
38 172
        return $clone;
39
    }
40
41 172
    public function build(HandlerInterface|CoreInterface $last): InterceptorPipeline
42
    {
43
        /** @psalm-suppress InvalidArgument */
44 172
        return $last instanceof HandlerInterface
45 164
            ? $this->pipeline->withHandler($last)
46 172
            : $this->pipeline->withCore($last);
47
    }
48
}
49