Passed
Branch master (60a40e)
by Alex
03:08
created

HttpExceptionAbstract   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 0%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 20
ccs 0
cts 8
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponse() 0 4 1
A getJsonResponse() 0 10 2
1
<?php
2
3
/**
4
 * Codeburner Framework.
5
 *
6
 * @author Alex Rohleder <[email protected]>
7
 * @copyright 2016 Alex Rohleder
8
 * @license http://opensource.org/licenses/MIT
9
 */
10
11
namespace Codeburner\Router\Exceptions\Http;
12
13
use Exception;
14
use Psr\Http\Message\ResponseInterface;
15
16
/**
17
 * Class HttpExceptionAbstract
18
 *
19
 * @author Alex Rohleder <[email protected]>
20
 */
21
22
abstract class HttpExceptionAbstract extends Exception
23
{
24
25
    public function getResponse(ResponseInterface $response)
26
    {
27
        return $response->withStatus($this->code, $this->message);
28
    }
29
30
    public function getJsonResponse(ResponseInterface $response)
31
    {
32
        $response->withAddedHeader("content-type", "application/json");
33
34
        if ($response->getBody()->isWritable()) {
35
            $response->getBody()->write(json_encode(["status-code" => $this->code, "reason-phrase" => $this->message]));
36
        }
37
38
        return $this->getResponse($response);
39
    }
40
41
}