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

SafeStorage::retrieveSafely()   A

Complexity

Conditions 2
Paths 2

Duplication

Lines 0
Ratio 0 %

Size

Total Lines 6
Code Lines 3

Importance

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