Completed
Push — master ( cd9922...3280a0 )
by Frank
02:34
created

SafeStorage::storeSafely()   A

Complexity

Conditions 1
Paths 1

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 4
Code Lines 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
dl 0
loc 4
rs 10
c 1
b 0
f 0
cc 1
eloc 2
nc 1
nop 2
1
<?php
2
3
namespace League\Flysystem;
4
5
final class SafeStorage
6
{
7
    /**
8
     * @var string
9
     */
10
    private $hash;
11
12
    /**
13
     * @var array
14
     */
15
    protected static $safeStorage = [];
16
17
    public function __construct()
18
    {
19
        $this->hash = spl_object_hash($this);
20
        static::$safeStorage[$this->hash] = [];
21
    }
22
23
    public function storeSafely($key, $value)
24
    {
25
        static::$safeStorage[$this->hash][$key] = $value;
26
    }
27
28
    public function retrieveSafely($key)
29
    {
30
        if (array_key_exists($key, static::$safeStorage[$this->hash])) {
31
            return static::$safeStorage[$this->hash][$key];
32
        }
33
    }
34
35
    public function __destruct()
36
    {
37
        unset(static::$safeStorage[$this->hash]);
38
    }
39
}
40