StorageFactory   A
last analyzed

Complexity

Total Complexity 4

Size/Duplication

Total Lines 20
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 8
c 1
b 0
f 0
dl 0
loc 20
ccs 7
cts 8
cp 0.875
rs 10
wmc 4

1 Method

Rating   Name   Duplication   Size   Complexity  
A create() 0 15 4
1
<?php
2
3
declare(strict_types=1);
4
5
/*
6
 * Copyright (c) Ne-Lexa
7
 *
8
 * For the full copyright and license information, please view
9
 * the LICENSE file that was distributed with this source code.
10
 *
11
 * @see https://github.com/Ne-Lexa/guzzle-doh-middleware
12
 */
13
14
namespace Nelexa\Doh\Storage;
15
16
use Psr\Cache\CacheItemPoolInterface;
17
use Psr\SimpleCache\CacheInterface;
18
19
final class StorageFactory
20
{
21
    /**
22
     * @param \Psr\SimpleCache\CacheInterface|\Psr\Cache\CacheItemPoolInterface|\Nelexa\Doh\Storage\StorageInterface|null $cache
23
     */
24 14
    public static function create($cache): StorageInterface
25
    {
26 14
        if ($cache instanceof StorageInterface) {
27
            return $cache;
28
        }
29
30 14
        if ($cache instanceof CacheInterface) {
31 1
            return new Psr16CacheStorage($cache);
32
        }
33
34 13
        if ($cache instanceof CacheItemPoolInterface) {
35 1
            return new Psr6CacheStorage($cache);
36
        }
37
38 12
        return new RuntimeStorage();
39
    }
40
}
41