Storage::save()   A
last analyzed

Complexity

Conditions 2
Paths 2

Size

Total Lines 6
Code Lines 4

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 4
CRAP Score 2

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 2
eloc 4
nc 2
nop 2
dl 0
loc 6
ccs 4
cts 4
cp 1
crap 2
rs 10
c 1
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_auth_sources\Sources\Files\Storages;
4
5
6
use kalanis\kw_auth_sources\AuthSourcesException;
7
use kalanis\kw_auth_sources\Interfaces\IKAusTranslations;
8
use kalanis\kw_auth_sources\Traits\TLang;
9
use kalanis\kw_files\FilesException;
10
use kalanis\kw_files\Traits\TToString;
11
use kalanis\kw_paths\PathsException;
12
use kalanis\kw_paths\Stuff;
13
use kalanis\kw_storage\Interfaces\IStorage;
14
use kalanis\kw_storage\StorageException;
15
16
17
/**
18
 * Class Storage
19
 * @package kalanis\kw_auth_sources\Sources\Files\Storages
20
 * Processing files in storage defined with interfaces from kw_storage
21
 */
22
class Storage extends AStorage
23
{
24
    use TLang;
25
    use TToString;
26
27
    protected IStorage $storage;
28
29 14
    public function __construct(IStorage $storage, ?IKAusTranslations $ausLang = null)
30
    {
31 14
        $this->storage = $storage;
32 14
        $this->setAusLang($ausLang);
33 14
    }
34
35 2
    protected function open(array $path): string
36
    {
37
        try {
38 2
            return $this->toString(Stuff::arrayToPath($path), $this->storage->read(Stuff::arrayToPath($path)));
39 1
        } catch (FilesException | StorageException | PathsException $ex) {
40 1
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
41
        }
42
    }
43
44 2
    protected function save(array $path, string $content): bool
45
    {
46
        try {
47 2
            return $this->storage->write(Stuff::arrayToPath($path), $content);
48 1
        } catch (StorageException | PathsException $ex) {
49 1
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
50
        }
51
    }
52
53
    /**
54
     * @return string
55
     * @codeCoverageIgnore translation
56
     */
57
    protected function noDirectoryDelimiterSet(): string
58
    {
59
        return $this->getAusLang()->kauNoDelimiterSet();
60
    }
61
}
62