InMemoryVersionStore   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 1

Importance

Changes 1
Bugs 0 Features 1
Metric Value
wmc 4
lcom 1
cbo 1
dl 0
loc 39
rs 10
c 1
b 0
f 1

3 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A persist() 0 4 1
A load() 0 9 2
1
<?php
2
/**
3
 * This file is part of the Cubiche package.
4
 *
5
 * Copyright (c) Cubiche
6
 *
7
 * For the full copyright and license information, please view the LICENSE
8
 * file that was distributed with this source code.
9
 */
10
11
namespace Cubiche\Domain\EventSourcing\Versioning;
12
13
use Cubiche\Core\Collections\ArrayCollection\ArrayHashMap;
14
15
/**
16
 * InMemoryVersionStore class.
17
 *
18
 * @author Ivannis Suárez Jerez <[email protected]>
19
 */
20
class InMemoryVersionStore implements VersionStoreInterface
21
{
22
    /**
23
     * @var ArrayHashMap
24
     */
25
    protected $store;
26
27
    /**
28
     * InMemoryVersionStore constructor.
29
     */
30
    public function __construct()
31
    {
32
        $this->store = new ArrayHashMap();
33
    }
34
35
    /**
36
     * @param string $aggregateClassName
37
     * @param int    $version
38
     */
39
    public function persist($aggregateClassName, $version)
40
    {
41
        $this->store->set($aggregateClassName, $version);
42
    }
43
44
    /**
45
     * @param string $aggregateClassName
46
     *
47
     * @return int
48
     */
49
    public function load($aggregateClassName)
50
    {
51
        $version = $this->store->get($aggregateClassName);
52
        if ($version !== null) {
53
            return $version;
54
        }
55
56
        return 0;
57
    }
58
}
59