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

Action   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

Changes 0
Metric Value
wmc 4
lcom 1
cbo 0
dl 0
loc 44
rs 10
c 0
b 0
f 0

9 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 10 1
init() 0 1 ?
performChecks() 0 1 ?
performAction() 0 1 ?
performCallBack() 0 1 ?
formatResponse() 0 1 ?
manageSlimeException() 0 1 ?
manageBaseException() 0 1 ?
A execute() 0 16 3
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