Completed
Push — master ( cf0590...09842b )
by Daniel
04:32
created

Metadata::remove()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 6
ccs 4
cts 4
cp 1
rs 9.4285
c 0
b 0
f 0
cc 2
eloc 3
nc 2
nop 1
crap 2
1
<?php
2
3
namespace DDDominio\EventSourcing\Common;
4
5
use DDDominio\Common\MetadataInterface;
6
7
class Metadata implements MetadataInterface
8
{
9
    /**
10
     * @var array
11
     */
12
    private $metadata = [];
13
14
    /**
15
     * @param array $metadata
16
     */
17 106
    public function __construct(array $metadata = [])
18
    {
19 106
        foreach ($metadata as $key => $values) {
20 14
            $this->set($key, $values);
21
        }
22 106
    }
23
24
    /**
25
     * @param string $key
26
     * @param string $value
27
     */
28 15
    public function set($key, $value)
29
    {
30 15
        $this->metadata[$key] = $value;
31 15
    }
32
33
    /**
34
     * @param string $key
35
     * @return mixed|null
36
     */
37 6
    public function get($key)
38
    {
39 6
        return $this->has($key) ? $this->metadata[$key] : null;
40
    }
41
42
    /**
43
     * @param string $key
44
     * @return bool
45
     */
46 6
    public function has($key)
47
    {
48 6
        return isset($this->metadata[$key]) || array_key_exists($key, $this->metadata);
49
    }
50
51
    /**
52
     * @param $key
53
     */
54 2
    public function remove($key)
55
    {
56 2
        if ($this->has($key)) {
57 1
            unset($this->metadata[$key]);
58
        }
59 2
    }
60
61
    /**
62
     * @return array
63
     */
64 44
    public function all()
65
    {
66 44
        return $this->metadata;
67
    }
68
69
    /**
70
     * {@inheritdoc}
71
     */
72 1
    public function getIterator()
73
    {
74 1
        return new \ArrayIterator($this->metadata);
75
    }
76
77
    /**
78
     * {@inheritdoc}
79
     */
80 1
    public function count()
81
    {
82 1
        return count($this->metadata);
83
    }
84
}
85