Completed
Push — master ( fceab7...09c4c4 )
by Fabian
13s
created

Dispatcher::responseIsSuccessful()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 2
nc 2
nop 1
crap 2
1
<?php
2
3
namespace IntegerNet\CallbackProxy;
4
5
use Psr\Http\Message\RequestInterface;
6
use Psr\Http\Message\ResponseInterface;
7
8
/**
9
 * Dispatches a request to multiple targets, returns first successful response (HTTP 200) or last response if none are
10
 * successful
11
 */
12
class Dispatcher
13
{
14
    /**
15
     * @var HttpClient
16
     */
17
    private $client;
18
    /**
19
     * @var Targets
20
     */
21
    private $targets;
22
    /**
23
     * @var DispatchStrategy
24
     */
25
    private $strategy;
26
27 48
    public function __construct(HttpClient $client, Targets $targets, DispatchStrategy $strategy)
28
    {
29 48
        $this->client = $client;
30 48
        $this->targets = $targets;
31 48
        $this->strategy = $strategy;
32 48
    }
33
34 48
    public function dispatch(RequestInterface $request, ResponseInterface $response, string $action): ResponseInterface
35
    {
36 48
        return $this->strategy->execute($this->client, $this->targets, $request, $response, $action);
37
    }
38
}
39