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

Metadata   A

Complexity

Total Complexity 10

Size/Duplication

Total Lines 68
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 10
lcom 1
cbo 0
dl 0
loc 68
ccs 17
cts 17
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 2
A set() 0 4 1
A get() 0 4 2
A has() 0 4 2
A all() 0 4 1
A getIterator() 0 4 1
A count() 0 4 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