Completed
Push — master ( 24802e...2ba5bb )
by Walter
02:16
created

Runtime::set()   A

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 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 0
loc 4
ccs 3
cts 3
cp 1
rs 10
cc 1
eloc 2
nc 1
nop 2
crap 1
1
<?php
2
/**
3
 * This file is part of phpab/phpab. (https://github.com/phpab/phpab)
4
 *
5
 * @link https://github.com/phpab/phpab for the canonical source repository
6
 * @copyright Copyright (c) 2015-2016 phpab. (https://github.com/phpab/)
7
 * @license https://raw.githubusercontent.com/phpab/phpab/master/LICENSE.md MIT
8
 */
9
10
namespace PhpAb\Storage\Adapter;
11
12
/**
13
 * Stores the participation state of the user only for the current request.
14
 *
15
 * @package PhpAb
16
 */
17
class Runtime implements AdapterInterface
18
{
19
    /**
20
     * @var array The data that has been set.
21
     */
22
    private $data;
23
24
    /**
25
     * Initializes a new instance of this class.
26
     *
27
     * @param array $data
28
     */
29 15
    public function __construct(array $data = [])
30
    {
31 15
        $this->data = $data;
32 15
    }
33
34
    /**
35
     * {@inheritDoc}
36
     */
37 16
    public function has($identifier)
38
    {
39 16
        return array_key_exists($identifier, $this->data);
40
    }
41
42
    /**
43
     * {@inheritDoc}
44
     */
45 14
    public function get($identifier)
46
    {
47 14
        if (!$this->has($identifier)) {
48 1
            return null;
49
        }
50
51 13
        return $this->data[$identifier];
52
    }
53
54
    /**
55
     * {@inheritDoc}
56
     */
57 12
    public function set($identifier, $value)
58
    {
59 12
        $this->data[$identifier] = $value;
60 12
    }
61
62
    /**
63
     * {@inheritDoc}
64
     */
65 2
    public function all()
66
    {
67 2
        return $this->data;
68
    }
69
70
    /**
71
     * {@inheritDoc}
72
     */
73 2
    public function remove($identifier)
74
    {
75 2
        if (!$this->has($identifier)) {
76 1
            return null;
77
        }
78
79 1
        $removedValue = $this->data[$identifier];
80
81 1
        unset($this->data[$identifier]);
82
83 1
        return $removedValue;
84
    }
85
86
    /**
87
     * {@inheritDoc}
88
     */
89 8
    public function clear()
90
    {
91 8
        $removedValues = $this->data;
92
93 8
        $this->data = [];
94
95 8
        return $removedValues;
96
    }
97
}
98