Factory   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 42
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 6
eloc 22
c 1
b 0
f 0
dl 0
loc 42
ccs 22
cts 22
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A getStorage() 0 26 5
1
<?php
2
3
namespace kalanis\kw_storage\Storage;
4
5
6
use kalanis\kw_storage\Interfaces;
7
use kalanis\kw_storage\StorageException;
8
9
10
/**
11
 * Class Factory
12
 * @package kalanis\kw_storage\Storage
13
 * Storage config factory class
14
 */
15
class Factory
16
{
17
    protected Target\Factory $targetFactory;
18
    protected Key\Factory $keyFactory;
19
20 15
    public function __construct(Key\Factory $keyFactory, Target\Factory $targetFactory)
21
    {
22 15
        $this->targetFactory = $targetFactory;
23 15
        $this->keyFactory = $keyFactory;
24
    }
25
26
    /**
27
     * @param object|array<string, string|object>|string|null $storageParams
28
     * @throws StorageException
29
     * @return Interfaces\IStorage|null
30
     */
31 14
    public function getStorage($storageParams): ?Interfaces\IStorage
32
    {
33 14
        if (is_object($storageParams) && ($storageParams instanceof Interfaces\IStorage)) {
34 1
            return $storageParams;
35
        }
36
37 13
        $storage = $this->targetFactory->getStorage($storageParams);
38 13
        if (empty($storage)) {
39 1
            return null;
40
        }
41
42 12
        if ($storage instanceof Interfaces\Target\ITargetVolume) {
43 1
            $publicStorage = new StorageDirs(
44 1
                $this->keyFactory->getKey($storage),
45 1
                $storage
46 1
            );
47 1
            $publicStorage->canUse();
48 1
            return $publicStorage;
49
50
        } else {
51 12
            $publicStorage = new Storage(
52 12
                $this->keyFactory->getKey($storage),
53 12
                $storage
54 12
            );
55 12
            $publicStorage->canUse();
56 12
            return $publicStorage;
57
        }
58
    }
59
}
60