Completed
Push — master ( 79d9f7...52fffe )
by Mauro
02:04
created

ApiError   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 16
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 2
c 1
b 0
f 0
lcom 0
cbo 2
dl 0
loc 16
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A __invoke() 0 13 2
1
<?php
2
3
namespace App\Handlers;
4
5
use Psr\Http\Message\ServerRequestInterface as Request;
6
use Psr\Http\Message\ResponseInterface as Response;
7
8
final class ApiError extends \Slim\Handlers\Error
9
{
10
    public function __invoke(Request $request, Response $response, \Exception $exception)
11
    {
12
        $status = $exception->getCode() ?: 500;
13
        $data = [
14
            "status" => "error",
15
            "message" => $exception->getMessage(),
16
        ];
17
        $body = json_encode($data, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT);
18
        return $response
19
                   ->withStatus($status)
20
                   ->withHeader("Content-type", "application/json")
21
                   ->write($body);
22
    }
23
}
24