Plugin   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 85
Duplicated Lines 0 %

Coupling/Cohesion

Components 2
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
dl 0
loc 85
ccs 18
cts 18
cp 1
rs 10
c 0
b 0
f 0
wmc 8
lcom 2
cbo 3

7 Methods

Rating   Name   Duplication   Size   Complexity  
A setRequest() 0 5 1
A getRequest() 0 7 2
A setResponse() 0 5 1
A getResponse() 0 7 2
A canHandle() 0 4 1
handle() 0 1 ?
A getName() 0 4 1
1
<?php
2
namespace FMUP\Dispatcher;
3
4
use FMUP\Environment;
5
use FMUP\Exception;
6
use FMUP\Request;
7
use FMUP\Response;
8
use FMUP\Sapi;
9
10
/**
11
 * Class Route - Route handling
12
 * @package FMUP\Routing
13
 */
14
abstract class Plugin
15
{
16
    use Environment\OptionalTrait, Sapi\OptionalTrait;
17
    /**
18
     * @var Request
19
     */
20
    private $request;
21
22
    /**
23
     * @var Response
24
     */
25
    private $response;
26
27
    /**
28
     * @var string
29
     */
30
    protected $name;
31
32
    /**
33
     * @param Request $request
34
     * @return $this
35
     */
36 6
    public function setRequest(Request $request)
37
    {
38 6
        $this->request = $request;
39 6
        return $this;
40
    }
41
42
    /**
43
     * @return Request
44
     * @throws Exception
45
     */
46 2
    public function getRequest()
47
    {
48 2
        if (!$this->request) {
49 1
            throw new Exception('Request not set');
50
        }
51 1
        return $this->request;
52
    }
53
54
    /**
55
     * @param Response $response
56
     * @return $this
57
     */
58 7
    public function setResponse(Response $response)
59
    {
60 7
        $this->response = $response;
61 7
        return $this;
62
    }
63
64
    /**
65
     * @return Response
66
     * @throws Exception
67
     */
68 7
    public function getResponse()
69
    {
70 7
        if (!$this->response) {
71 1
            throw new Exception('Response not set');
72
        }
73 6
        return $this->response;
74
    }
75
76
    /**
77
     * Check if plugin can handle request/response
78
     * @return bool
79
     */
80 1
    public function canHandle()
81
    {
82 1
        return true;
83
    }
84
85
    /**
86
     * Can be used to apply something on request object
87
     */
88
    abstract public function handle();
89
90
    /**
91
     * Get the name of the plugin
92
     * @return string
93
     */
94 4
    public function getName()
95
    {
96 4
        return $this->name;
97
    }
98
}
99