ExceptionMiddleware::execute()   A
last analyzed

Complexity

Conditions 5
Paths 5

Size

Total Lines 13
Code Lines 10

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 10
CRAP Score 5

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 10
c 1
b 0
f 0
dl 0
loc 13
ccs 10
cts 10
cp 1
rs 9.6111
cc 5
nc 5
nop 2
crap 5
1
<?php
2
0 ignored issues
show
Coding Style introduced by
Missing file doc comment
Loading history...
3
namespace DMT\Insolvency\Exception;
4
5
use DMT\CommandBus\Validator\ValidationException;
6
use DMT\Insolvency\Http\Request\GetReport;
7
use DMT\Insolvency\Http\Response\GetReportResponse;
8
use DMT\Insolvency\Soap\Request;
9
use DMT\Insolvency\Soap\Response;
10
use JMS\Serializer\Exception\Exception as SerializerException;
11
use League\Tactician\Middleware;
12
use Psr\Http\Client\ClientExceptionInterface;
13
14
/**
15
 * Class ExceptionMiddleware
16
 */
0 ignored issues
show
Coding Style introduced by
Missing @category tag in class comment
Loading history...
Coding Style introduced by
Missing @package tag in class comment
Loading history...
Coding Style introduced by
Missing @author tag in class comment
Loading history...
Coding Style introduced by
Missing @license tag in class comment
Loading history...
Coding Style introduced by
Missing @link tag in class comment
Loading history...
17
class ExceptionMiddleware implements Middleware
18
{
19
    /**
0 ignored issues
show
Coding Style introduced by
Missing short description in doc comment
Loading history...
20
     * @param Request|GetReport $command
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
21
     * @param callable $next
0 ignored issues
show
Coding Style introduced by
Missing parameter comment
Loading history...
Coding Style introduced by
Expected 10 spaces after parameter type; 1 found
Loading history...
Coding Style introduced by
Tag value for @param tag indented incorrectly; expected 2 spaces but found 1
Loading history...
22
     * @return Response|GetReportResponse
0 ignored issues
show
Coding Style introduced by
Tag @return cannot be grouped with parameter tags in a doc comment
Loading history...
23
     * @throws Exception
0 ignored issues
show
Coding Style introduced by
Tag @throws cannot be grouped with parameter tags in a doc comment
Loading history...
24
     */
25 16
    public function execute($command, callable $next)
26
    {
27
        try {
28
            /** @var Response|GetReportResponse $response */
0 ignored issues
show
Coding Style introduced by
The open comment tag must be the only content on the line
Loading history...
Coding Style introduced by
Missing short description in doc comment
Loading history...
Coding Style introduced by
The close comment tag must be the only content on the line
Loading history...
29 16
            return $next($command);
30 5
        } catch (Exception $exception) {
31 2
            throw $exception;
32 3
        } catch (ClientExceptionInterface $exception) {
33 1
            throw new UnavailableException($exception->getMessage(), 0, $exception);
34 2
        } catch (ValidationException $exception) {
35 1
            throw new RequestException($exception->getMessage(), 0, $exception);
36 1
        } catch (SerializerException $exception) {
37 1
            throw new UnavailableException($exception->getMessage(), 0, $exception);
38
        }
39
    }
40
}
41