Completed
Pull Request — 2.x (#80)
by
unknown
02:00
created

Session::regenerateId()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
nc 1
cc 1
eloc 2
nop 0
crap 1
1
<?php
2
/**
3
 *
4
 * This file is part of Aura for PHP.
5
 *
6
 * @license http://opensource.org/licenses/bsd-license.php BSD
7
 *
8
 */
9
namespace Aura\Auth\Session;
10
11
/**
12
 *
13
 * Session manager.
14
 *
15
 * @package Aura.Auth
16
 *
17
 */
18
class Session implements SessionInterface
19
{
20
    /**
21
     *
22
     * A copy of the $_COOKIE array.
23
     *
24
     * @var array
25
     *
26
     */
27
    protected $cookie;
28
29
    /**
30
     *
31
     * Constructor.
32
     *
33
     * @param array $cookie A copy of the $_COOKIE array.
34
     *
35
     */
36 22
    public function __construct(array $cookie)
37
    {
38 22
        $this->cookie = $cookie;
39 22
    }
40
41
    /**
42
     *
43
     * Starts a session.
44
     *
45
     * @return bool
46
     *
47
     */
48 3
    public function start()
49
    {
50 3
        return session_start();
51
    }
52
53
    /**
54
     *
55
     * Resumes a previously-started session.
56
     *
57
     * @return bool
58
     *
59
     */
60 2
    public function resume()
61
    {
62 2
        if (session_id() !== '') {
63 1
            return true;
64
        }
65
66 2
        if (isset($this->cookie[session_name()])) {
67 1
            return $this->start();
68
        }
69
70 1
        return false;
71
    }
72
73
    /**
74
     *
75
     * Regenerates a session ID.
76
     *
77
     * @return mixed
78
     *
79
     */
80 1
    public function regenerateId()
81
    {
82 1
        return session_regenerate_id(true);
83
    }
84
}
85