Presenter::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 4
nc 1
nop 2
dl 0
loc 6
ccs 0
cts 6
cp 0
crap 2
rs 9.4285
c 0
b 0
f 0
1
<?php
2
namespace Wandu\View;
3
4
use Psr\Http\Message\ServerRequestInterface;
5
use Wandu\DI\ContainerInterface;
6
use Wandu\View\Contacts\PresenterInterface;
7
8
class Presenter implements PresenterInterface
9
{
10
    /** @var \Wandu\DI\ContainerInterface */
11
    protected $container;
12
    
13
    /** @var \Psr\Http\Message\ServerRequestInterface */
14
    protected $request;
15
16
    /** @var \Wandu\Http\Contracts\SessionInterface */
17
    protected $session;
18
    
19
    /** @var string */
20
    protected $path = '';
21
22
    public function __construct(ContainerInterface $container, ServerRequestInterface $request)
23
    {
24
        $this->container = $container;
25
        $this->request = $request;
26
        $this->session = $request->getAttribute('session');
27
    }
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function render($template, array $values = [])
33
    {
34
        return render(
35
            $this->path . $template,
36
            $values + $this->getInitializeAttributes()
37
        );
38
    }
39
40
    /**
41
     * @return array
42
     */
43
    protected function getInitializeAttributes()
44
    {
45
        return [
46
            'container' => $this->container,
47
            'request' => $this->request,
48
            'session' => $this->session,
49
        ];
50
    }
51
}
52