DummyAdapter::saveStatus()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 0
Metric Value
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
c 0
b 0
f 0
cc 1
eloc 2
nc 1
nop 4
crap 1
1
<?php
2
declare(strict_types = 1);
3
4
5
namespace Paymaxi\Component\CircuitBreaker\Storage\Adapter;
6
7
use Paymaxi\Component\CircuitBreaker\Storage\StorageInterface;
8
9
/**
10
 * Does not really persist stats between requests!
11
 *
12
 * Can only be used for tests and as fallback instance.
13
 *
14
 * When real storage handler throws exception it means it cant be used any more.
15
 * Then storage user can safely fallback to this dummy instance.
16
 *
17
 * @see \Paymaxi\Component\CircuitBreaker\Storage\StorageInterface
18
 * @package Paymaxi\Component\CircuitBreaker\Components
19
 */
20
final class DummyAdapter implements StorageInterface
21
{
22
23
    /**
24
     * @var mixed[] Array of all the values (transient)
25
     */
26
    protected $data = array();
27
28
    /**
29
     * Loads circuit breaker service status value.
30
     *
31
     * @param    string $serviceName name of service to load stats for
32
     * @param    string $attributeName name of attribute to load
33
     *
34
     * @return    string  value stored or '' if value was not found
35
     */
36 13
    public function loadStatus($serviceName, $attributeName)
37
    {
38 13
        if (isset($this->data[$serviceName][$attributeName])) {
39 11
            return $this->data[$serviceName][$attributeName];
40
        }
41
42 11
        return "";
43
    }
44
45
    /**
46
     * Saves circuit breaker service status value.
47
     *
48
     * @param    string $serviceName name of service to load stats for
49
     * @param    string $attributeName name of the attribute to load
50
     * @param    string $value string value loaded or '' if nothing found
51
     * @param   boolean $flush set to true will force immediate save, false does not guaranteed saving at all.
52
     *
53
     * @return    void
54
     */
55 11
    public function saveStatus($serviceName, $attributeName, $value, $flush = false)
56
    {
57 11
        $this->data[$serviceName][$attributeName] = $value;
58 11
    }
59
60
}