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

SharedStorage::get()   A

Complexity

Conditions 2
Paths 2

Size

Total Lines 8
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 8
rs 9.4285
cc 2
eloc 4
nc 2
nop 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