SafeStorage   A
last analyzed

Complexity

Total Complexity 5

Size/Duplication

Total Lines 35
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 0

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 5
lcom 1
cbo 0
dl 0
loc 35
ccs 14
cts 14
cp 1
rs 10
c 0
b 0
f 0

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 5 1
A storeSafely() 0 4 1
A retrieveSafely() 0 6 2
A __destruct() 0 4 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 108
    public function __construct()
18
    {
19 108
        $this->hash = spl_object_hash($this);
20 108
        static::$safeStorage[$this->hash] = [];
21 108
    }
22
23 87
    public function storeSafely($key, $value)
24
    {
25 87
        static::$safeStorage[$this->hash][$key] = $value;
26 87
    }
27
28 93
    public function retrieveSafely($key)
29
    {
30 93
        if (array_key_exists($key, static::$safeStorage[$this->hash])) {
31 78
            return static::$safeStorage[$this->hash][$key];
32
        }
33 15
    }
34
35 108
    public function __destruct()
36
    {
37 108
        unset(static::$safeStorage[$this->hash]);
38 108
    }
39
}
40