ObjectKeyValue   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 59
Duplicated Lines 0 %

Importance

Changes 0
Metric Value
eloc 14
dl 0
loc 59
rs 10
c 0
b 0
f 0
wmc 9

7 Methods

Rating   Name   Duplication   Size   Complexity  
A getContent() 0 3 1
A set() 0 3 1
A exists() 0 3 1
A delete() 0 3 1
A get() 0 3 1
A __construct() 0 3 1
A wrap() 0 11 3
1
<?php
2
3
declare(strict_types=1);
4
5
namespace Lit\Nexus\Derived;
6
7
use Lit\Nexus\Interfaces\KeyValueInterface;
8
use Lit\Nexus\Traits\KeyValueTrait;
9
10
/**
11
 * KV object of an object content
12
 */
13
class ObjectKeyValue implements KeyValueInterface
14
{
15
    use KeyValueTrait;
16
17
    /**
18
     * @var object
19
     */
20
    protected $content;
21
22
    /**
23
     * ObjectKeyValue constructor.
24
     * @param object $content
25
     */
26
    protected function __construct($content)
27
    {
28
        $this->content = $content;
29
    }
30
31
32
    /**
33
     * @param object $content The content to be wrapped.
34
     * @return static
35
     */
36
    public static function wrap($content)
37
    {
38
        if ($content instanceof static) {
39
            return $content;
40
        }
41
42
        if (is_object($content)) {
43
            return new static($content);
44
        }
45
46
        throw new \InvalidArgumentException();
47
    }
48
49
    public function set(string $key, $value)
50
    {
51
        $this->content->{$key} = $value;
52
    }
53
54
    public function delete(string $key)
55
    {
56
        unset($this->content->{$key});
57
    }
58
59
    public function get(string $key)
60
    {
61
        return $this->content->{$key};
62
    }
63
64
    public function exists(string $key)
65
    {
66
        return isset($this->content->{$key});
67
    }
68
69
    public function getContent()
70
    {
71
        return $this->content;
72
    }
73
}
74