Completed
Push — master ( bbe443...f4a6ec )
by Tim
24:42 queued 09:39
created

SessionService   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 46
Duplicated Lines 0 %

Coupling/Cohesion

Components 0
Dependencies 1

Importance

Changes 0
Metric Value
wmc 4
lcom 0
cbo 1
dl 0
loc 46
c 0
b 0
f 0
rs 10

3 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 4 1
A get() 0 8 2
A set() 0 6 1
1
<?php
2
/**
3
 * Session Service
4
 *
5
 * @package Html5videoplayerPowermail\Service
6
 * @author  Tim Lochmüller
7
 */
8
9
namespace HVP\Html5videoplayerPowermail\Service;
10
11
/**
12
 * Session Service
13
 *
14
 * @author Tim Lochmüller
15
 */
16
class SessionService extends AbstractService
17
{
18
19
    /**
20
     * Check if the value exists
21
     *
22
     * @param string $name
23
     *
24
     * @return boolean
25
     */
26
    public function has($name)
27
    {
28
        return isset($_COOKIE[$name]);
29
    }
30
31
    /**
32
     * Get a vaukue
33
     *
34
     * @param string $name
35
     *
36
     * @return mixed|null
37
     */
38
    public function get($name)
39
    {
40
        if (!$this->has($name)) {
41
            return null;
42
        }
43
        return unserialize($_COOKIE[$name]);
44
45
    }
46
47
    /**
48
     * Set a value
49
     *
50
     * @param string $name
51
     * @param mixed  $value
52
     *
53
     * @return void
54
     */
55
    public function set($name, $value)
56
    {
57
        $setValue = serialize($value);
58
        setcookie($name, $setValue, null, '/');
59
        $_COOKIE[$name] = $setValue;
60
    }
61
}
62