CookieStorage::offsetExists()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 1
crap 1
1
<?php
2
3
/*
4
 * This file is part of the Lug package.
5
 *
6
 * (c) Eric GELOEN <[email protected]>
7
 *
8
 * For the full copyright and license information, please read the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Lug\Component\Storage\Model;
13
14
use Symfony\Component\HttpFoundation\ParameterBag;
15
use Symfony\Component\HttpFoundation\RequestStack;
16
17
/**
18
 * @author GeLo <[email protected]>
19
 */
20
class CookieStorage implements StorageInterface
21
{
22
    /**
23
     * @var RequestStack
24
     */
25
    private $requestStack;
26
27
    /**
28
     * @param RequestStack $requestStack
29
     */
30 5
    public function __construct(RequestStack $requestStack)
31
    {
32 5
        $this->requestStack = $requestStack;
33 5
    }
34
35
    /**
36
     * {@inheritdoc}
37
     */
38 1
    public function offsetExists($offset)
39
    {
40 1
        return $this->getCookies()->has($offset);
41
    }
42
43
    /**
44
     * {@inheritdoc}
45
     */
46 1
    public function offsetGet($offset)
47
    {
48 1
        return $this->getCookies()->get($offset);
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function offsetSet($offset, $value)
55
    {
56 1
        $this->getCookies()->set($offset, $value);
57 1
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function offsetUnset($offset)
63
    {
64 1
        $this->getCookies()->remove($offset);
65 1
    }
66
67
    /**
68
     * @return ParameterBag
69
     */
70 4
    private function getCookies()
71
    {
72 4
        return $this->requestStack->getMasterRequest()->cookies;
73
    }
74
}
75