Passed
Push — master ( bb7b0f...8f1ad4 )
by Daniel
03:05
created

Metadata::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 5
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 2

Importance

Changes 0
Metric Value
dl 0
loc 5
ccs 3
cts 3
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 78
    public function __construct(array $metadata = [])
18
    {
19 78
        foreach ($metadata as $key => $values) {
20 12
            $this->set($key, $values);
21
        }
22 78
    }
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 isset($this->metadata[$key]) ?
40 4
            $this->metadata[$key] : null;
41
    }
42
43
    /**
44
     * @return array
45
     */
46 30
    public function all()
47
    {
48 30
        return $this->metadata;
49
    }
50
51
    /**
52
     * {@inheritdoc}
53
     */
54 1
    public function getIterator()
55
    {
56 1
        return new \ArrayIterator($this->metadata);
57
    }
58
59
    /**
60
     * {@inheritdoc}
61
     */
62 1
    public function count()
63
    {
64 1
        return count($this->metadata);
65
    }
66
}
67