Completed
Push — master ( ad39ae...0b4736 )
by Vincenzo
02:16
created

Action::execute()   A

Complexity

Conditions 3
Paths 7

Size

Total Lines 16
Code Lines 12

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 16
rs 9.4285
c 0
b 0
f 0
cc 3
eloc 12
nc 7
nop 0
1
<?php
2
3
4
namespace App\Lib\Slime\RestAction;
5
6
7
use App\Lib\Slime\Exceptions\SlimeException;
8
use App\Lib\Slime\Interfaces\UseCase\IAction;
9
use Psr\Http\Message\RequestInterface;
10
use Psr\Http\Message\ResponseInterface;
11
12
abstract class Action implements IAction
13
{
14
    protected $args;
15
    protected $request;
16
    protected $response;
17
18
    public function __construct(
19
        RequestInterface $request = null,
20
        ResponseInterface $response = null,
21
        array $args = []
22
    )
23
    {
24
        $this->args = $args;
25
        $this->request = $request;
26
        $this->response = $response;
27
    }
28
29
    public function execute()
30
    {
31
        $this->init();
32
        try {
33
            $this->performChecks();
34
            $this->performAction();
35
            $this->performCallBack();
36
        } catch (SlimeException $slimeException) {
37
            $this->manageSlimeException($slimeException);
38
        } catch (\Exception $baseException) {
39
            $this->manageBaseException($baseException);
40
        }
41
42
        $this->formatResponse();
43
        return $this->response;
44
    }
45
46
    protected abstract function init();
47
    protected abstract function performChecks();
48
    protected abstract function performAction();
49
    protected abstract function performCallBack();
50
    protected abstract function formatResponse();
51
    protected abstract function manageSlimeException(SlimeException $slimeException);
52
    protected abstract function manageBaseException(\Exception $baseException);
53
54
55
}
56