PdoSessionModule   A
last analyzed

Complexity

Total Complexity 2

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 4
Bugs 1 Features 0
Metric Value
wmc 2
c 4
b 1
f 0
lcom 1
cbo 2
dl 0
loc 39
ccs 12
cts 12
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A configure() 0 10 1
1
<?php
2
3
namespace Ray\SymfonySessionModule;
4
5
use Ray\Di\AbstractModule;
6
use Ray\Di\Scope;
7
use Ray\SymfonySessionModule\Annotation\SessionOptions;
8
use Ray\SymfonySessionModule\Annotation\SessionStorage;
9
use Symfony\Component\HttpFoundation\Session\SessionInterface;
10
use Symfony\Component\HttpFoundation\Session\Storage\Handler\PdoSessionHandler;
11
12
class PdoSessionModule extends AbstractModule
13
{
14
    /**
15
     * @var \PDO
16
     */
17
    private $pdo;
18
19
    /**
20
     * @var array
21
     */
22
    private $options;
23
24
    /**
25
     * Constructor.
26
     *
27
     * @param \PDO  $pdo
28
     * @param array $options
29
     */
30 1
    public function __construct(\PDO $pdo, array $options = [])
31
    {
32 1
        $this->pdo = $pdo;
33 1
        $this->options = $options;
34 1
        parent::__construct();
35 1
    }
36
37
    /**
38
     * {@inheritdoc}
39
     */
40 1
    protected function configure()
41
    {
42 1
        $this->pdo->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION);
43 1
        $this->bind()->annotatedWith(SessionStorage::class)->toInstance($this->pdo);
44 1
        $this->bind(\SessionHandlerInterface::class)->toConstructor(PdoSessionHandler::class, 'pdoOrDsn=' . SessionStorage::class);
45
46 1
        $this->bind()->annotatedWith(SessionOptions::class)->toInstance($this->options);
47
48 1
        $this->bind(SessionInterface::class)->toProvider(SessionProvider::class)->in(Scope::SINGLETON);
49 1
    }
50
}
51