Passed
Push — master ( 76d3e9...73f345 )
by Radu
01:24
created

Cookie::set()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 17
Code Lines 8

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 17
rs 9.4285
c 0
b 0
f 0
cc 1
eloc 8
nc 1
nop 7
1
<?php
2
namespace WebServCo\Framework\Libraries;
3
4
use WebServCo\Framework\RequestUtils as Utils;
5
6
final class Cookie extends \WebServCo\Framework\AbstractLibrary
7
{
8
    public function __construct($config)
9
    {
10
        parent::__construct($config);
11
    }
12
    
13
    public function set(
14
        $name,
15
        $value = '',
16
        $expire = 0,
17
        $path = '',
18
        $domain = '',
19
        $secure = false,
20
        $httponly = false
21
    ) {
22
        return setcookie(
23
            $name,
24
            Utils::sanitizeString($value),
25
            $expire,
26
            $path,
27
            $domain,
28
            $secure,
29
            $httponly
30
        );
31
    }
32
    
33
    public function get($name)
34
    {
35
        return isset($_COOKIE[$name]) ? $_COOKIE[$name] : false;
36
    }
37
    
38
    public function remove($name)
39
    {
40
        if (!isset($_COOKIE[$name])) {
41
            return false;
42
        }
43
        
44
        unset($_COOKIE[$name]);
45
        $this->set($name, false, -1);
46
        return true;
47
    }
48
}
49