Config   A
last analyzed

Complexity

Total Complexity 3

Size/Duplication

Total Lines 63
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 3
lcom 1
cbo 2
dl 0
loc 63
ccs 23
cts 23
cp 1
rs 10
c 0
b 0
f 0

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
B define() 0 28 2
1
<?php
2
/**
3
 * Aura\Session Provider for Aura\Di
4
 *
5
 * PHP version 5
6
 *
7
 * Copyright (C) 2016 Jake Johns
8
 *
9
 * This software may be modified and distributed under the terms
10
 * of the MIT license.  See the LICENSE file for details.
11
 *
12
 * @category  Config
13
 * @package   Fusible\SessionProvider
14
 * @author    Jake Johns <[email protected]>
15
 * @copyright 2016 Jake Johns
16
 * @license   http://jnj.mit-license.org/2016 MIT License
17
 * @link      https://github.com/fusible/fusible.session-provider
18
 */
19
20
namespace Fusible\SessionProvider;
21
22
use Aura\Di\Container;
23
use Aura\Di\ContainerConfig;
24
25
use Aura\Session;
26
27
/**
28
 * Config
29
 *
30
 * @category Config
31
 * @package  Fusible\SessionProvider
32
 * @author   Jake Johns <[email protected]>
33
 * @license  http://jnj.mit-license.org/2016 MIT License
34
 * @link     https://github.com/fusible/fusible.session-provider
35
 *
36
 * @see ContainerConfig
37
 */
38
class Config extends ContainerConfig
39
{
40
    /**
41
     * Cookie
42
     *
43
     * @var array
44
     *
45
     * @access protected
46
     */
47
    protected $cookie;
48
49
    /**
50
     * __construct
51
     *
52
     * @param array $cookie Cookie array
53
     *
54
     * @access public
55
     */
56 4
    public function __construct(array $cookie = null)
57
    {
58 4
        $this->cookie = $cookie ?? $_COOKIE;
59 4
    }
60
61
    /**
62
     * Define Aura\Session factories and services
63
     *
64
     * @param Container $di DI Container
65
     *
66
     * @return void
67
     *
68
     * @access public
69
     *
70
     * @SuppressWarnings(PHPMD.ShortVariable)
71
     */
72 4
    public function define(Container $di)
73
    {
74 4
        if (! isset($di->values[Cookie::class])) {
75 4
            $di->values[Cookie::class] = $this->cookie;
76 4
        }
77
78 4
        $di->set(
79
            Session\SessionFactory::class,
80 4
            $di->lazyNew(Session\SessionFactory::class)
81 4
        );
82 4
83 4
        $di->set(
84 4
            Session\Session::class,
85 4
            $di->lazyGetCall(
86 4
                Session\SessionFactory::class,
87 4
                'newInstance',
88
                $di->lazyValue(Cookie::class)
89 4
            )
90 4
        );
91 4
92 4
        $di->set(
93
            Session\CsrfToken::class,
94 4
            $di->lazyGetCall(
95 4
                Session\Session::class,
96 4
                'getCsrfToken'
97
            )
98
        );
99
    }
100
}
101