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

TStorage::setStorage()   A

Complexity

Conditions 2
Paths 4

Size

Total Lines 8
Code Lines 6

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 6
CRAP Score 2

Importance

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