Executor   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 26
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 2
Bugs 0 Features 0
Metric Value
wmc 5
eloc 9
c 2
b 0
f 0
dl 0
loc 26
ccs 11
cts 11
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A execute() 0 17 4
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