AppendToStreamResponseInspector   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 5
c 1
b 0
f 0
lcom 0
cbo 4
dl 0
loc 37
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
B inspect() 0 29 5
1
<?php
2
3
namespace RayRutjes\GetEventStore\Client\Http;
4
5
use Psr\Http\Message\ResponseInterface;
6
use RayRutjes\GetEventStore\Client\Exception\WrongExpectedVersionException;
7
8
class AppendToStreamResponseInspector extends AbstractResponseInspector
9
{
10
    /**
11
     * @param ResponseInterface $response
12
     *
13
     * @throws BadRequestException
14
     */
15
    public function inspect(ResponseInterface $response)
16
    {
17
        $this->filterCommonErrors($response);
18
        switch ($response->getStatusCode()) {
19
20
            /* OK */
21
            case 201:
22
                break;
23
24
            /*
25
             * The ES Api will try to redirect us if we do not provide an eventId.
26
             * Actually this client is designed to avoid that scenario.
27
             * The httpClient does not allow redirects anyway.
28
             * See: http://docs.geteventstore.com/http-api/3.4.0/writing-to-a-stream/#expected-version
29
             */
30
            case 301:
31
                throw new \LogicException('Please help us understand how you got here!!!');
32
33
            /* Catch known error, otherwise fall-through to a more generic exception. */
34
            case 400:
35
                if ($response->getReasonPhrase() == 'Wrong expected EventNumber') {
36
                    throw new WrongExpectedVersionException();
37
                }
38
39
            /* KO. */
40
            default:
41
                throw $this->newBadRequestException($response);
42
        }
43
    }
44
}
45