Passed
Push — master ( 7c7732...5d308c )
by Stone
03:35
created

Cookie   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 30
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 4
dl 0
loc 30
rs 10
c 0
b 0
f 0
wmc 3

3 Methods

Rating   Name   Duplication   Size   Complexity  
A setCookie() 0 3 1
A getCookie() 0 3 1
A deleteCookie() 0 3 1
1
<?php
2
3
namespace Core\Dependency;
4
5
class Cookie{
6
7
    /**
8
     * set a cookie
9
     * @param string $name
10
     * @param string $value
11
     * @param string $expireDate
12
     */
13
    public function setCookie(string $name, string $value, string $expireDate):void
14
    {
15
        setcookie($name, $value, $expireDate, "/");
0 ignored issues
show
Bug introduced by
$expireDate of type string is incompatible with the type integer expected by parameter $expire of setcookie(). ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-type  annotation

15
        setcookie($name, $value, /** @scrutinizer ignore-type */ $expireDate, "/");
Loading history...
16
    }
17
18
    /**
19
     * delete a named cookie
20
     * @param string $name
21
     */
22
    public function deleteCookie(string $name):void
23
    {
24
        setcookie($name, "", time()-3600); //expire the cookie
25
    }
26
27
    /**
28
     * get a cookie
29
     * @param string $name
30
     * @return mixed
31
     */
32
    public function getCookie(string $name)
33
    {
34
        return $_COOKIE[$name] ?? false;
35
36
    }
37
}