InMemoryStorage   A
last analyzed

Complexity

Total Complexity 9

Size/Duplication

Total Lines 75
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 9
lcom 1
cbo 3
dl 0
loc 75
ccs 21
cts 21
cp 1
rs 10
c 0
b 0
f 0

7 Methods

Rating   Name   Duplication   Size   Complexity  
A add() 0 10 2
A contains() 0 4 1
A containsId() 0 4 1
A findById() 0 8 2
A remove() 0 4 1
A removeById() 0 6 1
A all() 0 4 1
1
<?php
2
3
/*
4
 * This file is part of Transfer.
5
 *
6
 * For the full copyright and license information, please view the LICENSE file located
7
 * in the root directory.
8
 */
9
10
namespace Transfer\Storage;
11
12
use Transfer\Storage\Exception\ObjectNotFoundException;
13
14
/**
15
 * In-memory storage.
16
 */
17
class InMemoryStorage extends AbstractStorage
18
{
19
    /**
20
     * @var array
21
     */
22
    private $data = array();
23
24
    /**
25
     * {@inheritdoc}
26
     */
27 22
    public function add($object, $id = null)
28
    {
29 22
        if ($id === null) {
30 9
            $id = $this->hashingStrategy->hash($object);
31 9
        }
32
33 22
        $this->data[$id] = $object;
34
35 22
        return true;
36
    }
37
38
    /**
39
     * {@inheritdoc}
40
     */
41 1
    public function contains($object)
42
    {
43 1
        return $this->containsId($this->hashingStrategy->hash($object));
44
    }
45
46
    /**
47
     * {@inheritdoc}
48
     */
49 11
    public function containsId($id)
50
    {
51 11
        return array_key_exists($id, $this->data);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57 10
    public function findById($id)
58
    {
59 10
        if (!$this->containsId($id)) {
60 1
            throw new ObjectNotFoundException($id);
61
        }
62
63 9
        return $this->data[$id];
64
    }
65
66
    /**
67
     * {@inheritdoc}
68
     */
69 4
    public function remove($object)
70
    {
71 4
        return $this->removeById($this->hashingStrategy->hash($object));
72
    }
73
74
    /**
75
     * {@inheritdoc}
76
     */
77 6
    public function removeById($id)
78
    {
79 6
        unset($this->data[$id]);
80
81 6
        return true;
82
    }
83
84
    /**
85
     * {@inheritdoc}
86
     */
87 12
    public function all()
88
    {
89 12
        return $this->data;
90
    }
91
}
92