Completed
Push — master ( 6d12c1...fefd2b )
by Vincenzo
03:27
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
c 0
b 0
f 0
dl 0
loc 16
rs 9.4285
cc 3
eloc 12
nc 7
nop 0
1
<?php
2
3
4
namespace App\Lib\Slime\RestAction\UseCase;
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
    protected $expectedQueryParameters = [
19
20
    ];
21
22
    public function __construct(
23
        RequestInterface $request = null,
24
        ResponseInterface $response = null,
25
        array $args = []
26
    )
27
    {
28
        $this->args = $args;
29
        $this->request = $request;
30
        $this->response = $response;
31
    }
32
33
    public function execute()
34
    {
35
        $this->init();
36
        try {
37
            $this->performChecks();
38
            $this->performAction();
39
            $this->performCallBack();
40
        } catch (SlimeException $slimeException) {
41
            $this->manageSlimeException($slimeException);
42
        } catch (\Exception $baseException) {
43
            $this->manageBaseException($baseException);
44
        }
45
46
        $this->formatResponse();
47
        return $this->response;
48
    }
49
50
    protected abstract function init();
51
    protected abstract function performChecks();
52
    protected abstract function performAction();
53
    protected abstract function performCallBack();
54
    protected abstract function formatResponse();
55
    protected abstract function manageSlimeException(SlimeException $slimeException);
56
    protected abstract function manageBaseException(\Exception $baseException);
57
58
}
59