Test Failed
Push — master ( d89333...e2d202 )
by Alexey
03:26
created

CookieJar::put()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 4
c 0
b 0
f 0
ccs 0
cts 4
cp 0
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 2
1
<?php declare(strict_types = 1);
2
3
namespace Venta\Http;
4
5
use DateInterval;
6
use DateTime;
7
use DateTimeInterface;
8
use Venta\Contracts\Http\Cookie as CookieContract;
9
use Venta\Contracts\Http\CookieJar as CookieJarContract;
10
11
/**
12
 * Class CookieJar
13
 *
14
 * @package Venta\Http
15
 */
16
class CookieJar implements CookieJarContract
17
{
18
19
    /**
20
     * @var CookieContract[]
21
     */
22
    private $cookies = [];
23
24
    /**
25
     * @inheritDoc
26
     */
27 View Code Duplication
    public function add(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
28
        string $name,
29
        string $value,
30
        DateTimeInterface $expires,
31
        string $path = '',
32
        string $domain = '',
33
        bool $secure = false,
34
        bool $httpOnly = false
35
    ) {
36
        $this->put(new Cookie($name, $value, $expires, $path, $domain, $secure, $httpOnly));
37
    }
38
39
    /**
40
     * @inheritDoc
41
     */
42
    public function all(): array
43
    {
44
        return $this->cookies;
45
    }
46
47
    /**
48
     * @inheritDoc
49
     */
50
    public function findByName(string $name)
51
    {
52
        return $this->cookies[$name] ?? null;
53
    }
54
55
    /**
56
     * @inheritDoc
57
     */
58
    public function forever(
59
        string $name,
60
        string $value = null,
61
        string $path = '',
62
        string $domain = '',
63
        bool $secure = false,
64
        bool $httpOnly = false
65
    ) {
66
        $this->add($name, $value, (new DateTime())->add(new DateInterval('P10Y')), $path, $domain, $secure, $httpOnly);
67
    }
68
69
    /**
70
     * @inheritDoc
71
     */
72
    public function forget(string $name)
73
    {
74
        $this->add($name, '', (new DateTime())->setTimestamp(1));
75
    }
76
77
    /**
78
     * @inheritDoc
79
     */
80
    public function put(CookieContract $cookie)
81
    {
82
        $this->cookies[$cookie->name()] = $cookie;
83
    }
84
85
    /**
86
     * @inheritDoc
87
     */
88 View Code Duplication
    public function session(
0 ignored issues
show
Duplication introduced by
This method seems to be duplicated in your project.

Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.

You can also find more detailed suggestions in the “Code” section of your repository.

Loading history...
89
        string $name,
90
        string $value,
91
        string $path = '',
92
        string $domain = '',
93
        bool $secure = false,
94
        bool $httpOnly = false
95
    ) {
96
        $this->put(new Cookie($name, $value, null, $path, $domain, $secure, $httpOnly));
97
    }
98
99
100
}