Session::terminate()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 1
eloc 2
c 1
b 0
f 1
nc 1
nop 0
dl 0
loc 4
ccs 0
cts 4
cp 0
crap 2
rs 10
1
<?php
2
namespace JayaCode\Framework\Core\Session;
3
4
use Symfony\Component\HttpFoundation\Session\Session as SessionBase;
5
6
class Session extends SessionBase
7
{
8
    private $flash = array();
9
    private $flashNew = array();
10
11
    public function start()
12
    {
13
        $storage = $this->storage->start();
14
15
        $this->initFlash();
16
        return $storage;
17
    }
18
19
    public function initFlash()
20
    {
21
        $this->flash = (array) $this->get("flash", array());
22
        $this->set("flash", array());
23
    }
24
25
    private function moveNewFlashToFlash()
26
    {
27
        $this->set("flash", $this->flashNew);
28
    }
29
30
    public function setFlash($name, $value)
31
    {
32
        $this->flashNew[$name] = $value;
33
    }
34
35
    public function getFlash($name = null)
36
    {
37
        if (is_null($name)) {
38
            return array_merge($this->flash, $this->flashNew);
39
        }
40
41
        $value = arr_get($this->flashNew, $name);
42
        if (!$value) {
43
            $value = arr_get($this->flash, $name);
44
        }
45
46
        return $value;
47
    }
48
49
    /**
50
     * @param $name
51
     * @return bool
52
     */
53
    public function hasFlash($name)
54
    {
55
        return null !== $this->getFlash($name);
56
    }
57
58
    public function terminate()
59
    {
60
        $this->moveNewFlashToFlash();
61
    }
62
}
63