Passed
Pull Request — master (#42)
by Korotkov
02:47
created

Cookie   A

Complexity

Total Complexity 4

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 7
c 0
b 0
f 0
dl 0
loc 37
rs 10
wmc 4

4 Methods

Rating   Name   Duplication   Size   Complexity  
A has() 0 3 1
A unset() 0 4 1
A get() 0 3 1
A set() 0 3 1
1
<?php
2
3
declare(strict_types=1);
4
5
/**
6
 * @author    : Jagepard <[email protected]">
7
 * @copyright Copyright (c) 2019, Jagepard
8
 * @license   https://mit-license.org/ MIT
9
 */
10
11
namespace Rudra\Container;
12
13
use Rudra\Container\Interfaces\CookieInterface;
14
15
class Cookie implements CookieInterface
16
{
17
    /**
18
     * @param string $key
19
     * @return string
20
     */
21
    public function get(string $key): string
22
    {
23
        return $_COOKIE[$key];
24
    }
25
26
    /**
27
     * @param string $key
28
     * @return bool
29
     */
30
    public function has(string $key): bool
31
    {
32
        return isset($_COOKIE[$key]);
33
    }
34
35
    /**
36
     * @codeCoverageIgnore
37
     * @param string $key
38
     */
39
    public function unset(string $key): void
40
    {
41
        unset($_COOKIE[$key]);
42
        setcookie($key, '', -1, '/');
43
    }
44
45
    /**
46
     * @param string $key
47
     * @param string $value
48
     */
49
    public function set(string $key, string $value): void
50
    {
51
        $_COOKIE[$key] = $value;
52
    }
53
}
54