Executor::execute()   A
last analyzed

Complexity

Conditions 4
Paths 3

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 9
CRAP Score 4

Importance

Changes 2
Bugs 0 Features 0
Metric Value
cc 4
eloc 8
c 2
b 0
f 0
nc 3
nop 2
dl 0
loc 17
ccs 9
cts 9
cp 1
crap 4
rs 10
1
<?php
2
3
namespace CHStudio\Raven;
4
5
use CHStudio\Raven\Validator\Expectation\ExpectationCollection;
6
use CHStudio\Raven\Validator\RequestValidatorInterface;
7
use CHStudio\Raven\Validator\ResponseValidatorInterface;
8
use Psr\Http\Client\ClientInterface;
9
use Psr\Http\Message\RequestInterface;
10
11
class Executor implements ExecutorInterface
12
{
13 3
    public function __construct(
14
        private readonly ClientInterface $client,
15
        private readonly RequestValidatorInterface $requestValidator,
16
        private readonly ResponseValidatorInterface $responseValidator
17
    ) {
18 3
    }
19
20 2
    public function execute(
21
        RequestInterface $request,
22
        ExpectationCollection $expectations = null
23
    ): void {
24 2
        $this->requestValidator->validate($request);
25 2
        $response = $this->client->sendRequest($request);
26
27 2
        if ($expectations !== null) {
28 2
            foreach ($expectations as $expectation) {
29 2
                $error = $expectation->verify($response);
30 2
                if ($error !== null) {
31 1
                    throw $error;
32
                }
33
            }
34
        }
35
36 1
        $this->responseValidator->validate($response, $request);
37
    }
38
}
39