Passed
Pull Request — master (#10)
by Korotkov
01:41
created

ContainerCookieTrait   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 38
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
dl 0
loc 38
rs 10
c 0
b 0
f 0
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A setCookie() 0 3 1
A hasCookie() 0 3 1
A getCookie() 0 3 1
A unsetCookie() 0 4 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Korotkov Danila <[email protected]>
7
 * @copyright Copyright (c) 2016, Korotkov Danila
8
 * @license   http://www.gnu.org/licenses/gpl.html GNU GPLv3.0
9
 */
10
11
namespace Rudra\Traits;
12
13
/**
14
 * Trait ContainerCookieTrait
15
 * @package Rudra
16
 */
17
trait ContainerCookieTrait
18
{
19
20
    /**
21
     * @param string $key
22
     * @return string
23
     */
24
    public function getCookie(string $key): string
25
    {
26
        return $_COOKIE[$key];
27
    }
28
29
    /**
30
     * @param string $key
31
     * @return bool
32
     */
33
    public function hasCookie(string $key): bool
34
    {
35
        return isset($_COOKIE[$key]);
36
    }
37
38
    /**
39
     * @codeCoverageIgnore
40
     * @param string $key
41
     */
42
    public function unsetCookie(string $key): void
43
    {
44
        unset($_COOKIE[$key]);
45
        setcookie($key, '', -1, '/');
46
    }
47
48
    /**
49
     * @param string $key
50
     * @param string $value
51
     */
52
    public function setCookie(string $key, string $value): void
53
    {
54
        $_COOKIE[$key] = $value;
55
    }
56
}
57