SessionAdapter::__unset()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 0
Metric Value
cc 1
eloc 1
c 0
b 0
f 0
nc 1
nop 1
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_input\Simplified;
4
5
6
use ArrayIterator;
7
use kalanis\kw_input\Interfaces;
8
use kalanis\kw_input\Traits;
9
use Traversable;
10
11
12
/**
13
 * Class SessionAdapter
14
 * @package kalanis\kw_input\Extras
15
 * Accessing _SESSION via ArrayAccess
16
 */
17
class SessionAdapter implements Interfaces\IFilteredInputs
18
{
19
    use Traits\TFill;
20
21
    /**
22
     * @param string|int $offset
23
     * @return mixed
24
     */
25 1
    public final function __get($offset)
26
    {
27 1
        return $this->offsetGet($offset);
28
    }
29
30
    /**
31
     * @param string|int $offset
32
     * @param mixed|null $value
33
     */
34 2
    public final function __set($offset, $value): void
35
    {
36 2
        $this->offsetSet($offset, $value);
37
    }
38
39
    /**
40
     * @param string|int $offset
41
     * @return bool
42
     */
43 1
    public final function __isset($offset): bool
44
    {
45 1
        return $this->offsetExists($offset);
46
    }
47
48
    /**
49
     * @param string|int $offset
50
     */
51 2
    public final function __unset($offset): void
52
    {
53 2
        $this->offsetUnset($offset);
54
    }
55
56 1
    public final function offsetExists($offset): bool
57
    {
58 1
        return isset($_SESSION[$this->removeNullBytes(strval($offset))]);
59
    }
60
61
    #[\ReturnTypeWillChange]
62 1
    public final function offsetGet($offset)
63
    {
64 1
        return $_SESSION[$this->removeNullBytes(strval($offset))];
65
    }
66
67 2
    public final function offsetSet($offset, $value): void
68
    {
69 2
        $_SESSION[$this->removeNullBytes(strval($offset))] = $value;
70
    }
71
72 2
    public final function offsetUnset($offset): void
73
    {
74 2
        unset($_SESSION[$this->removeNullBytes(strval($offset))]);
75
    }
76
77 2
    public function getIterator(): Traversable
78
    {
79 2
        return new ArrayIterator(
80 2
            $this->fillFromEntries(Interfaces\IEntry::SOURCE_SESSION, $_SESSION),
81 2
            ArrayIterator::STD_PROP_LIST | ArrayIterator::ARRAY_AS_PROPS
82 2
        );
83
    }
84
}
85