SessionProvider::__construct()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 1

Importance

Changes 2
Bugs 0 Features 1
Metric Value
c 2
b 0
f 1
dl 0
loc 5
ccs 4
cts 4
cp 1
rs 9.4285
cc 1
eloc 3
nc 1
nop 2
crap 1
1
<?php
2
3
namespace Ray\SymfonySessionModule;
4
5
use Ray\Di\ProviderInterface;
6
use Ray\SymfonySessionModule\Annotation\SessionOptions;
7
use Symfony\Component\HttpFoundation\Session\Session;
8
use Symfony\Component\HttpFoundation\Session\SessionInterface;
9
use Symfony\Component\HttpFoundation\Session\Storage\NativeSessionStorage;
10
11
class SessionProvider implements ProviderInterface
12
{
13
    /**
14
     * @var \SessionHandlerInterface
15
     */
16
    private $handler;
17
18
    /**
19
     * @var array
20
     */
21
    private $options;
22
23
    /**
24
     * Constructor
25
     *
26
     * @param \SessionHandlerInterface $handler
27
     * @param array                    $options
28
     *
29
     * @SessionOptions("options")
30
     */
31 1
    public function __construct(\SessionHandlerInterface $handler, array $options = [])
32
    {
33 1
        $this->handler = $handler;
34 1
        $this->options = $options;
35 1
    }
36
37
    /**
38
     * @return SessionInterface
39
     */
40 1
    public function get()
41
    {
42 1
        $storage = new NativeSessionStorage($this->options, $this->handler);
43
44 1
        return new Session($storage);
45
    }
46
}
47