Passed
Pull Request — main (#7)
by Anatoly
02:56
created

Json::offsetSet()   A

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 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 3
rs 10
ccs 2
cts 2
cp 1
crap 1
1
<?php declare(strict_types=1);
2
3
/**
4
 * It's free open-source software released under the MIT License.
5
 *
6
 * @author Anatoly Fenric <[email protected]>
7
 * @copyright Copyright (c) 2021, Anatoly Fenric
8
 * @license https://github.com/sunrise-php/hydrator/blob/master/LICENSE
9
 * @link https://github.com/sunrise-php/hydrator
10
 */
11
12
namespace Sunrise\Hydrator;
13
14
/**
15
 * Import classes
16
 */
17
use ArrayAccess;
18
use JsonSerializable;
19
20
/**
21
 * Import functions
22
 */
23
use function array_key_exists;
24
25
/**
26
 * Json
27
 */
28
class Json implements ArrayAccess, JsonSerializable
29
{
30
    protected array $data;
31
32
    /**
33
     * Constructor of the class
34
     */
35 3
    public function __construct(array $data)
36
    {
37 3
        $this->data = $data;
38 3
    }
39
40
    /**
41
     * {@inheritdoc}
42
     */
43 1
    public function offsetExists($offset) : bool
44
    {
45 1
        return array_key_exists($offset, $this->data);
46
    }
47
48
    /**
49
     * {@inheritdoc}
50
     */
51 2
    public function offsetGet($offset)
52
    {
53 2
        return $this->data[$offset] ?? null;
54
    }
55
56
    /**
57
     * {@inheritdoc}
58
     */
59 2
    public function offsetSet($offset, $value) : void
60
    {
61 2
        $this->data[$offset] = $value;
62 2
    }
63
64
    /**
65
     * {@inheritdoc}
66
     */
67 1
    public function offsetUnset($offset) : void
68
    {
69 1
        unset($this->data[$offset]);
70 1
    }
71
72
    /**
73
     * {@inheritdoc}
74
     */
75 1
    public function jsonSerialize() : array
76
    {
77 1
        return $this->data;
78
    }
79
}
80