Passed
Push — master ( 96eda9...4e4eee )
by Petr
07:51
created

ArrayDirKey   A

Complexity

Total Complexity 3

Size/Duplication

Total Lines 25
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 3
eloc 9
c 1
b 0
f 0
dl 0
loc 25
ccs 8
cts 8
cp 1
rs 10

2 Methods

Rating   Name   Duplication   Size   Complexity  
A fromSharedKey() 0 3 1
A __construct() 0 7 2
1
<?php
2
3
namespace kalanis\kw_storage\Storage\Key;
4
5
6
use kalanis\kw_storage\Interfaces\IKey;
7
use kalanis\kw_storage\Interfaces\IStTranslations;
8
use kalanis\kw_storage\StorageException;
9
use kalanis\kw_storage\Traits\TLang;
10
11
12
/**
13
 * Class ArrayDirKey
14
 * @package kalanis\kw_storage\Key
15
 * Added prefix path - in form of array
16
 * Check if dir exists
17
 */
18
class ArrayDirKey implements IKey
19
{
20
    use TLang;
21
22
    /** @var string */
23
    protected $prefix = '';
24
25
    /**
26
     * @param string[] $prefix
27
     * @param IStTranslations|null $lang
28
     * @throws StorageException
29
     */
30 2
    public function __construct(array $prefix, ?IStTranslations $lang = null)
31
    {
32 2
        $this->setStLang($lang);
33 2
        if ($pt = realpath(implode(DIRECTORY_SEPARATOR, $prefix))) {
34 1
            $this->prefix = strval($pt);
35
        } else {
36 1
            throw new StorageException($this->getStLang()->stPathNotFound());
37
        }
38 1
    }
39
40 1
    public function fromSharedKey(string $key): string
41
    {
42 1
        return $this->prefix . $key;
43
    }
44
}
45