Completed
Push — master ( f65d8f...4f3de5 )
by Pavel
04:14 queued 01:54
created

JsonException::encodeError()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 13
Code Lines 9

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
eloc 9
nc 1
nop 0
dl 0
loc 13
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace App\Common;
3
4
use \Neomerx\JsonApi\Encoder\Encoder;
5
use \Neomerx\JsonApi\Document\Error;
6
7
class JsonException extends \Exception
8
{
9
    /**
10
     * @var
11
     */
12
    public $statusCode;
13
14
    /**
15
     * @var string
16
     */
17
    private $type;
18
19
    /**
20
     * @var string
21
     */
22
    private $title;
23
24
    /**
25
     * @var string
26
     */
27
    private $detail;
28
29
    /**
30
     * JsonException constructor.
31
     *
32
     * @param string $type
33
     * @param int    $statusCode
34
     * @param string $title
35
     * @param string $detail
36
     */
37
    public function __construct($type, $statusCode, $title, $detail)
38
    {
39
        $this->statusCode = $statusCode;
40
        $this->type       = $type;
41
        $this->title      = $title;
42
        $this->detail     = $detail;
43
    }
44
45
    /**
46
     * JsonApi encode error
47
     *
48
     * @return string
49
     */
50
    public function encodeError()
51
    {
52
        $error = new Error(
53
            $this->type,
54
            null,
55
            $this->statusCode,
56
            $this->statusCode,
57
            $this->title,
58
            $this->detail
59
        );
60
61
        return Encoder::instance()->encodeError($error);
62
    }
63
}