ResponseResolver   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 44
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Importance

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

3 Methods

Rating   Name   Duplication   Size   Complexity  
A getResponseProxyInstance() 0 8 2
A setViewEngineConfig() 0 3 1
B resolve() 0 23 6
1
<?php
2
3
namespace App\ViewResolver;
4
5
use Core\View\ViewResolverInterface;
6
use Core\Utils\ResponseProxy;
7
use Psr\Http\Message\ResponseInterface;
8
9
class ResponseResolver implements ViewResolverInterface
10
{
11
    /**
12
     * @var ResponseProxy
13
     */
14
    private static $responseProxy = null;
15
16
    public static function getResponseProxyInstance()
17
    {
18
        if (self::$responseProxy === null) {
19
            self::$responseProxy = new ResponseProxy();
20
        }
21
22
        return self::$responseProxy;
23
    }
24
25
    public function setViewEngineConfig(array $settings)
26
    {
27
    }
28
29
    public function resolve($viewData)
30
    {
31
        if (self::$responseProxy === null || self::$responseProxy->getResponse() === null) {
32
            return;
33
        }
34
35
        /** @var ResponseInterface */
36
        $response = self::$responseProxy->getResponse();
37
38
        if ($response->getStatusCode()) {
39
            header(sprintf('HTTP/%s %d %s',
40
                $response->getProtocolVersion(),
41
                $response->getStatusCode(),
42
                $response->getReasonPhrase()
43
            ));
44
        }
45
46
        foreach ($response->getHeaders() as $name => $values) {
47
            foreach ($values as $value) {
48
                header($name . ':' . $value);
49
            }
50
        }
51
    }
52
}
53