Test Setup Failed
Push — master ( 8fa0e2...251f8c )
by Gabriel
08:50
created

HasResolverPipelineTrait::buildCallPipeline()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace Nip\Dispatcher\Resolver;
4
5
use League\Pipeline\InterruptibleProcessor;
6
use League\Pipeline\Pipeline;
7
use Nip\Dispatcher\Commands\Command;
8
use Nip\Dispatcher\Exceptions\ForwardException;
9
use Nip\Dispatcher\Resolver\Pipeline\ActionBuilder;
10
use Nip\Dispatcher\Resolver\Pipeline\Stages\StageInterface;
11
use Psr\Http\Message\ResponseInterface;
12
13
/**
14
 * Trait HasResolverPipelineTrait
15
 * @package Nip\Dispatcher\Resolver
16
 */
17
trait HasResolverPipelineTrait
18
{
19
    /**
20
     * @var Pipeline[]
21
     */
22
    protected $resolverPipeline = [];
23
24
    /**
25
     * @param Command $command
26
     * @return Command
27
     * @throws ForwardException
28
     */
29 3
    protected function processCommand(Command $command)
30
    {
31 3
        $pipeline = $this->getResolverPipeline();
32 3
        return $pipeline->process($command);
33
    }
34
35
    /**
36
     * @param string $type
37
     * @return Pipeline
38
     */
39 4
    public function getResolverPipeline($type = ActionBuilder::class)
40
    {
41 4
        if (!isset($this->resolverPipeline[$type])) {
42 4
            $this->initResolverPipeline($type);
43
        }
44 4
        return $this->resolverPipeline[$type];
45
    }
46
47
    /**
48
     * @param string $type
49
     */
50 4
    protected function initResolverPipeline($type)
51
    {
52 4
        $this->resolverPipeline[$type] = $this->getResolverBuilder($type)->build();
53 4
    }
54
55
    /**
56
     * @param $type
57
     * @return ActionBuilder
58
     */
59 4
    protected function getResolverBuilder($type)
60
    {
61 4
        return (new $type());
62
    }
63
}
64