Completed
Push — master ( 55daec...2d65d3 )
by Kamil
18:26
created

SharedStorage   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 53
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Importance

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

4 Methods

Rating   Name   Duplication   Size   Complexity  
A getLatestResource() 0 8 2
A setClipboard() 0 4 1
A get() 0 8 2
A set() 0 5 1
1
<?php
2
3
/*
4
 * This file is part of the Sylius package.
5
 *
6
 * (c) Paweł Jędrzejewski
7
 *
8
 * For the full copyright and license information, please view the LICENSE
9
 * file that was distributed with this source code.
10
 */
11
12
namespace Sylius\Component\Core\Test\Services;
13
14
/**
15
 * @author Arkadiusz Krakowiak <[email protected]>
16
 */
17
class SharedStorage implements SharedStorageInterface
18
{
19
    /**
20
     * @var array
21
     */
22
    private $clipboard = [];
23
24
    /**
25
     * @var string|null
26
     */
27
    private $latestKey = null;
28
29
    /**
30
     * {@inheritdoc}
31
     */
32
    public function get($key)
33
    {
34
        if (!isset($this->clipboard[$key])) {
35
            throw new \InvalidArgumentException(sprintf('There is no current resource for "%s"!', $key));
36
        }
37
38
        return $this->clipboard[$key];
39
    }
40
41
    /**
42
     * {@inheritdoc}
43
     */
44
    public function set($key, $resource)
45
    {
46
        $this->clipboard[$key] = $resource;
47
        $this->latestKey = $key;
48
    }
49
50
    /**
51
     * {@inheritdoc}
52
     */
53
    public function getLatestResource()
54
    {
55
        if (!isset($this->clipboard[$this->latestKey])) {
56
            throw new \InvalidArgumentException(sprintf('There is no latest resource!', $this->latestKey));
57
        }
58
59
        return $this->clipboard[$this->latestKey];
60
    }
61
62
    /**
63
     * {@inheritdoc}
64
     */
65
    public function setClipboard(array $clipboard)
66
    {
67
        $this->clipboard = $clipboard;
68
    }
69
}
70