Completed
Push — master ( 101884...dadcb3 )
by Restu
15:34
created

Session::getFlash()   A

Complexity

Conditions 3
Paths 3

Size

Total Lines 13
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 1
Metric Value
cc 3
eloc 7
c 1
b 0
f 1
nc 3
nop 1
dl 0
loc 13
rs 9.4285
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 = $this->get("flash", array());
0 ignored issues
show
Documentation Bug introduced by
It seems like $this->get('flash', array()) of type * is incompatible with the declared type array of property $flash.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
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