InMemoryVersionStore::load()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 9
Code Lines 5

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
dl 0
loc 9
rs 9.6666
c 0
b 0
f 0
cc 2
eloc 5
nc 2
nop 1
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