InMemoryRepository   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 4

Importance

Changes 0
Metric Value
wmc 6
lcom 1
cbo 4
dl 0
loc 53
rs 10
c 0
b 0
f 0

5 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 6 1
A get() 0 4 1
A persist() 0 5 1
A persistAll() 0 6 2
A remove() 0 5 1
1
<?php
2
3
/**
4
 * This file is part of the Cubiche package.
5
 *
6
 * Copyright (c) Cubiche
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
namespace Cubiche\Domain\Repository\InMemory;
12
13
use Cubiche\Core\Collections\ArrayCollection\ArraySet;
14
use Cubiche\Core\Specification\Criteria;
15
use Cubiche\Domain\Model\IdInterface;
16
use Cubiche\Domain\Repository\Repository;
17
18
/**
19
 * InMemoryRepository Class.
20
 *
21
 * @author Ivannis Suárez Jerez <[email protected]>
22
 * @author Karel Osorio Ramírez <[email protected]>
23
 */
24
class InMemoryRepository extends Repository
25
{
26
    /**
27
     * @var ArraySet
28
     */
29
    protected $collection;
30
31
    /**
32
     * @param string $entityName
33
     */
34
    public function __construct($entityName)
35
    {
36
        parent::__construct($entityName);
37
38
        $this->collection = new ArraySet();
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function get(IdInterface $id)
45
    {
46
        return $this->collection->findOne(Criteria::method('id')->eq($id));
47
    }
48
49
    /**
50
     * {@inheritdoc}
51
     */
52
    public function persist($element)
53
    {
54
        $this->checkType($element);
55
        $this->collection->add($element);
56
    }
57
58
    /**
59
     * {@inheritdoc}
60
     */
61
    public function persistAll($elements)
62
    {
63
        foreach ($elements as $element) {
64
            $this->persist($element);
65
        }
66
    }
67
68
    /**
69
     * {@inheritdoc}
70
     */
71
    public function remove($element)
72
    {
73
        $this->checkType($element);
74
        $this->collection->remove($element);
75
    }
76
}
77