Passed
Push — master ( f05083...ef147e )
by Gabriel
11:42
created

Cookie   A

Complexity

Total Complexity 12

Size/Duplication

Total Lines 86
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
wmc 12
eloc 26
c 0
b 0
f 0
dl 0
loc 86
rs 10

9 Methods

Rating   Name   Duplication   Size   Complexity  
A setPath() 0 5 1
A setSecured() 0 5 1
A setValue() 0 5 1
A setExpire() 0 5 1
A isExpired() 0 6 3
A setDomain() 0 5 1
A getExpire() 0 3 1
A save() 0 11 2
A setExpireTimer() 0 5 1
1
<?php
2
3
namespace Bytic\Cookie;
4
5
class Cookie extends \Symfony\Component\HttpFoundation\Cookie
6
{
7
    /**
8
     * @param $value
9
     * @return $this
10
     */
11
    public function setValue($value): self
12
    {
13
        $this->value = $value;
14
15
        return $this;
16
    }
17
18
    /**
19
     * @param $domain
20
     * @return $this
21
     */
22
    public function setDomain($domain): self
23
    {
24
        $this->domain = $domain;
25
26
        return $this;
27
    }
28
29
    public function setPath($path): self
30
    {
31
        $this->path = $path;
32
33
        return $this;
34
    }
35
36
    public function setExpire($expire)
37
    {
38
        $this->expire = $expire;
39
40
        return $this;
41
    }
42
43
    /**
44
     * @return int
45
     */
46
    public function getExpire()
47
    {
48
        return $this->getExpiresTime();
49
    }
50
51
    public function setExpireTimer($expires)
52
    {
53
        $this->expire = time() + $expires;
54
55
        return $this;
56
    }
57
58
    public function setSecured($secured)
59
    {
60
        $this->secure = $secured;
61
62
        return $this;
63
    }
64
65
    /**
66
     * @return bool
67
     */
68
    public function isExpired(): bool
69
    {
70
        if (is_int($this->expire) && $this->expire < time()) {
71
            return true;
72
        } else {
73
            return false;
74
        }
75
    }
76
77
    /**
78
     * @return bool
79
     */
80
    public function save(): bool
81
    {
82
        $domain = ($this->getDomain() != 'localhost') ? $this->getDomain() : false;
83
84
        return setcookie(
85
                $this->getName(),
86
                $this->getValue(),
87
                $this->getExpire(),
88
                $this->getPath(),
89
                $domain,
0 ignored issues
show
Bug introduced by
It seems like $domain can also be of type false; however, parameter $domain of setcookie() does only seem to accept string, maybe add an additional type check? ( Ignorable by Annotation )

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

89
                /** @scrutinizer ignore-type */ $domain,
Loading history...
90
                $this->isSecure());
91
    }
92
}
93