ArrayDirKey::fromSharedKey()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 1
crap 1
1
<?php
2
3
namespace kalanis\kw_storage\Storage\Key;
4
5
6
use kalanis\kw_storage\Interfaces\IStTranslations;
7
use kalanis\kw_storage\Interfaces\Target\IKey;
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
    protected string $prefix = '';
23
24
    /**
25
     * @param string[] $prefix
26
     * @param IStTranslations|null $lang
27
     * @throws StorageException
28
     */
29 2
    public function __construct(array $prefix, ?IStTranslations $lang = null)
30
    {
31 2
        $this->setStLang($lang);
32 2
        if ($pt = realpath(implode(DIRECTORY_SEPARATOR, $prefix))) {
33 1
            $this->prefix = strval($pt);
34
        } else {
35 1
            throw new StorageException($this->getStLang()->stPathNotFound());
36
        }
37
    }
38
39 1
    public function fromSharedKey(string $key): string
40
    {
41 1
        return $this->prefix . $key;
42
    }
43
}
44