ExceptionMiddleware   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 34
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 6
eloc 13
dl 0
loc 34
c 0
b 0
f 0
ccs 13
cts 13
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 3 1
A execute() 0 12 5
1
<?php
2
3
namespace DMT\WebservicesNl\Client\Command\Middleware;
4
5
use DMT\CommandBus\Validator\ValidationException;
6
use DMT\WebservicesNl\Client\Exception\ExceptionInterface;
7
use DMT\WebservicesNl\Client\Exception\ExceptionHandler;
8
use GuzzleHttp\Exception\RequestException;
9
use League\Tactician\Middleware;
10
11
/**
12
 * Class ExceptionMiddleware
13
 *
14
 * @package DMT\WebservicesNl\Client
15
 */
16
class ExceptionMiddleware implements Middleware
17
{
18
    /**
19
     * @var ExceptionHandler
20
     */
21
    protected $exceptionHandler;
22
23
    /**
24
     * ExceptionMiddleware constructor.
25
     */
26 20
    public function __construct()
27
    {
28 20
        $this->exceptionHandler = new ExceptionHandler();
29 20
    }
30
31
    /**
32
     * @param object $command
33
     * @param callable $next
34
     *
35
     * @return mixed
36
     * @throws ExceptionInterface
37
     */
38 18
    public function execute($command, callable $next)
39
    {
40
        try {
41 18
            return $next($command);
42 18
        } catch (ExceptionInterface $exception) {
43 4
            throw $exception;
44 14
        } catch (ValidationException $exception) {
45 1
            $this->exceptionHandler->throwServiceExceptionFromViolationException($exception);
46 13
        } catch (RequestException $exception) {
47 6
            $this->exceptionHandler->throwServiceExceptionFromRequestException($exception);
48 7
        } catch (\Throwable $exception) {
49 7
            $this->exceptionHandler->throwServiceException($exception);
50
        }
51
    }
52
}
53