StorageFactory::create()   A
last analyzed

Complexity

Conditions 4
Paths 4

Size

Total Lines 15
Code Lines 7

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 7
CRAP Score 4.0312

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 4
eloc 7
c 1
b 0
f 0
nc 4
nop 1
dl 0
loc 15
ccs 7
cts 8
cp 0.875
crap 4.0312
rs 10
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