SessionManagerFactory   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 4

Test Coverage

Coverage 0%

Importance

Changes 3
Bugs 0 Features 0
Metric Value
wmc 3
c 3
b 0
f 0
lcom 0
cbo 4
dl 0
loc 30
ccs 0
cts 19
cp 0
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A __invoke() 0 20 2
1
<?php
2
namespace Staticus\Auth\Factories;
3
4
use Staticus\Auth\SaveHandlers\Redis;
5
use Staticus\Config\ConfigInterface;
6
use Zend\Session\Config\SessionConfig;
7
use Zend\Session\SessionManager;
8
9
class SessionManagerFactory
10
{
11
    protected $config;
12
13
    public function __construct(ConfigInterface $config)
14
    {
15
        $this->config = $config->get('auth.session');
16
    }
17
18
    public function __invoke()
19
    {
20
        $sessionConfig = new SessionConfig();
21
        $sessionConfig->setOptions($this->config['options']);
22
        $sessionManager = new SessionManager($sessionConfig);
23
        if (class_exists(\Redis::class)) {
24
            $saveHandler = new Redis(
25
                $this->config['redis']['host'],
26
                $this->config['redis']['port'],
27
                $this->config['redis']['password']
28
            );
29
            $sessionManager->setSaveHandler($saveHandler);
30
            $sessionManager->start();
31
        } else {
32
            trigger_error('Redis extension is not found. '
33
                . \Staticus\Auth\AuthSessionMiddleware::class . ' will not work.', E_USER_NOTICE);
34
        }
35
36
        return $sessionManager;
37
    }
38
}
39