Completed
Pull Request — master (#58)
by Thijs
04:00
created

ArrayAccessor::offsetUnset()   A

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
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
4
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
5
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
6
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
7
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
8
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
9
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
10
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
11
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
12
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
13
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
14
 *
15
 * This software consists of voluntary contributions made by many individuals
16
 * and is licensed under the MIT license.
17
 */
18
19
declare(strict_types = 1);
20
21
namespace PSR7Sessions\Storageless\Session;
22
23
/**
24
 * Class ArrayAccessor
25
 *
26
 * Wrapper class around SessionInterface with ArrayAccess Interface
27
 */
28
class ArrayAccessor implements \ArrayAccess
29
{
30
    /**
31
     * @var SessionInterface
32
     */
33
    private $session;
34
35
    /**
36
     * ArrayAccessor constructor.
37
     *
38
     * @param SessionInterface $session
39
     */
40 6
    public function __construct(SessionInterface $session)
41
    {
42 6
        $this->session = $session;
43 6
    }
44
45
    /**
46
     * Proxy function to SessionInterface
47
     *
48
     * @param string $method
49
     * @param array  $args
50
     *
51
     * @return mixed
52
     */
53 1
    public function __call($method, $args)
54
    {
55 1
        return call_user_func_array([$this->session, $method], $args);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61 1
    public function offsetExists($offset)
62
    {
63 1
        return $this->session->has($offset);
64
    }
65
66
    /**
67
     * Offset to retrieve.
68
     *
69
     * @link  http://php.net/manual/en/arrayaccess.offsetget.php
70
     *
71
     * @param string $offset
72
     * @param null   $default
73
     *
74
     * @return array|bool|float|int|mixed|string
75
     */
76 1
    public function offsetGet($offset, $default = null)
77
    {
78 1
        return $this->session->get($offset, $default);
79
    }
80
81
    /**
82
     * {@inheritdoc}
83
     */
84 1
    public function offsetSet($offset, $value)
85
    {
86 1
        return $this->session->set($offset, $value);
87
    }
88
89
    /**
90
     * {@inheritdoc}
91
     */
92 1
    public function offsetUnset($offset)
93
    {
94 1
        return $this->session->remove($offset);
95
    }
96
}