Passed
Push — master ( 38aca6...759f4d )
by Petr
03:02
created

TStorage   A

Complexity

Total Complexity 5

Size/Duplication

Total Lines 37
Duplicated Lines 0 %

Test Coverage

Coverage 84.62%

Importance

Changes 0
Metric Value
eloc 12
dl 0
loc 37
ccs 11
cts 13
cp 0.8462
rs 10
c 0
b 0
f 0
wmc 5

3 Methods

Rating   Name   Duplication   Size   Complexity  
A clearStorage() 0 3 1
A setStorage() 0 8 2
A getStorage() 0 8 2
1
<?php
2
3
namespace kalanis\kw_mapper\Storage\Storage;
4
5
6
use kalanis\kw_mapper\MapperException;
7
use kalanis\kw_storage\Interfaces\IStorage;
8
use kalanis\kw_storage\StorageException;
9
10
11
/**
12
 * Trait TStorage
13
 * @package kalanis\kw_mapper\Storage\Storage
14
 */
15
trait TStorage
16
{
17
    /**
18
     * Set another storage than usually called local volume
19
     * @param object|array<string, string|object>|string $storageParams
20
     * @throws MapperException
21
     */
22 17
    protected function setStorage($storageParams = 'volume'): void
23
    {
24
        try {
25 17
            $instance = StorageSingleton::getInstance();
26 17
            $instance->clearStorage();
27 17
            $instance->getStorage($storageParams);
28 1
        } catch (StorageException $ex) {
29 1
            throw new MapperException($ex->getMessage(), $ex->getCode(), $ex);
30
        }
31 16
    }
32
33
    /**
34
     * @throws MapperException
35
     * @return IStorage
36
     */
37 14
    protected function getStorage(): IStorage
38
    {
39
        try {
40 14
            return StorageSingleton::getInstance()->getStorage('volume');
41
            // @codeCoverageIgnoreStart
42
        } catch (StorageException $ex) {
43
            // means you have failed storage - larger problem than "only" unknown storage
44
            throw new MapperException($ex->getMessage(), $ex->getCode(), $ex);
45
        }
46
        // @codeCoverageIgnoreEnd
47
    }
48
49 1
    protected function clearStorage(): void
50
    {
51 1
        StorageSingleton::getInstance()->clearStorage();
52 1
    }
53
}
54