Completed
Push — master ( dece2f...058db9 )
by Daniel
04:22
created

Metadata::getIterator()   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 0
Metric Value
dl 0
loc 4
ccs 2
cts 2
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 0
crap 1
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 102
    public function __construct(array $metadata = [])
18
    {
19 102
        foreach ($metadata as $key => $values) {
20 12
            $this->set($key, $values);
21
        }
22 102
    }
23
24
    /**
25
     * @param string $key
26
     * @param string $value
27
     */
28 13
    public function set($key, $value)
29
    {
30 13
        $this->metadata[$key] = $value;
31 13
    }
32
33
    /**
34
     * @param string $key
35
     * @return mixed|null
36
     */
37 4
    public function get($key)
38
    {
39 4
        return $this->has($key) ? $this->metadata[$key] : null;
40
    }
41
42
    /**
43
     * @param string $key
44
     * @return bool
45
     */
46 4
    public function has($key)
47
    {
48 4
        return isset($this->metadata[$key]) || array_key_exists($key, $this->metadata);
49
    }
50
51
    /**
52
     * @return array
53
     */
54 40
    public function all()
55
    {
56 40
        return $this->metadata;
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function getIterator()
63
    {
64 1
        return new \ArrayIterator($this->metadata);
65
    }
66
67
    /**
68
     * {@inheritdoc}
69
     */
70 1
    public function count()
71
    {
72 1
        return count($this->metadata);
73
    }
74
}
75