Completed
Push — master ( dcf652...3d17c5 )
by Vincenzo
02:18
created

ApiAction::manageBaseException()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 5
rs 9.4285
cc 1
eloc 3
nc 1
nop 1
1
<?php
2
3
4
namespace App\Actions;
5
6
7
use App\Lib\Helpers\Responder;
8
use App\Lib\Slime\Exceptions\SlimeException;
9
use App\Lib\Slime\RestAction\Action;
10
11
abstract class ApiAction extends Action
12
{
13
    protected $code;
14
    protected $message;
15
    protected $payload;
16
17
    protected function init()
18
    {
19
        $this->code = 200;
20
        $this->message = "OK";
21
        $this->payload = null;
22
    }
23
24
    protected function performChecks()
25
    {
26
27
    }
28
29
    protected function performCallBack()
30
    {
31
32
    }
33
34
    protected function formatResponse()
35
    {
36
        $bodyContent = json_encode(
37
            [
38
                'code' => $this->code,
39
                'message' => $this->message,
40
                'payload' => $this->payload
41
            ]
42
        );
43
44
        $this->response = Responder::getJsonResponse(
45
            $bodyContent,
46
            $this->response
47
        );
48
    }
49
50
    protected function manageSlimeException(SlimeException $slimeException)
51
    {
52
        $this->manageBaseException($slimeException);
53
    }
54
55
    protected function manageBaseException(\Exception $baseException)
56
    {
57
        $this->code = $baseException->getCode();
58
        $this->message = $baseException->getMessage();
59
    }
60
}