Passed
Branch dev (8e1e05)
by Alex
03:51
created

RequestResponseStrategy   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 27
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 5

Test Coverage

Coverage 75%

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 3
c 1
b 0
f 1
lcom 1
cbo 5
dl 0
loc 27
ccs 6
cts 8
cp 0.75
rs 10

1 Method

Rating   Name   Duplication   Size   Complexity  
A call() 0 15 3
1
<?php
2
3
/**
4
 * Codeburner Framework.
5
 *
6
 * @author Alex Rohleder <[email protected]>
7
 * @copyright 2016 Alex Rohleder
8
 * @license http://opensource.org/licenses/MIT
9
 */
10
11
namespace Codeburner\Router\Strategies;
12
13
use Psr\Http\Message\ResponseInterface;
14
use Codeburner\Router\Exceptions\Http\HttpExceptionAbstract;
15
use Codeburner\Router\Route;
16
17
/**
18
 * The RequestResponseStrategy give an instance of Psr\Http\Message\RequestInterface,
19
 * Psr\Http\Message\Response interface and one array with parameters from pattern.
20
 *
21
 * @author Alex Rohleder <[email protected]>
22
 */
23
24
class RequestResponseStrategy implements StrategyInterface
25
{
26
27
    use RequestAwareTrait;
28
29
    /**
30
     * @inheritdoc
31
     * @return ResponseInterface
32
     */
33
34 2
    public function call(Route $route)
35
    {
36
        try {
37 2
            $response = call_user_func($route->getAction(), $this->request, $this->response, $route->getMergedParams());
38
39 2
            if ($response instanceof ResponseInterface) {
40 1
                return $response;
41
            }
42
43 1
            $this->response->getBody()->write((string) $response);
44 1
            return $this->response;
45
        } catch (HttpExceptionAbstract $e) {
46
            return $e->getResponse($this->response);
47
        }
48
    }
49
50
}
51