Files   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 86.67%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 16
c 1
b 0
f 0
dl 0
loc 39
ccs 13
cts 15
cp 0.8667
rs 10
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A save() 0 6 2
A __construct() 0 5 1
A open() 0 6 2
A noDirectoryDelimiterSet() 0 3 1
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\Interfaces\IFLTranslations;
11
use kalanis\kw_files\Interfaces\IProcessFiles;
12
use kalanis\kw_files\Traits\TToString;
13
use kalanis\kw_paths\PathsException;
14
use kalanis\kw_paths\Stuff;
15
16
17
/**
18
 * Class Files
19
 * @package kalanis\kw_auth_sources\Sources\Files\Storages
20
 * Processing files in storage defined with interfaces from kw_files
21
 */
22
class Files extends AStorage
23
{
24
    use TLang;
25
    use TToString;
26
27
    protected IProcessFiles $files;
28
29 7
    public function __construct(IProcessFiles $files, ?IKAusTranslations $ausLang = null, ?IFLTranslations $flLang = null)
30
    {
31 7
        $this->files = $files;
32 7
        $this->setAusLang($ausLang);
33 7
        $this->setFlLang($flLang); // TToString
34 7
    }
35
36 2
    protected function open(array $path): string
37
    {
38
        try {
39 2
            return $this->toString(Stuff::arrayToPath($path), $this->files->readFile($path));
40 1
        } catch (FilesException | PathsException $ex) {
41 1
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
42
        }
43
    }
44
45 2
    protected function save(array $path, string $content): bool
46
    {
47
        try {
48 2
            return $this->files->saveFile($path, $content);
49 1
        } catch (FilesException | PathsException $ex) {
50 1
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
51
        }
52
    }
53
54
    /**
55
     * @return string
56
     * @codeCoverageIgnore translation
57
     */
58
    protected function noDirectoryDelimiterSet(): string
59
    {
60
        return $this->getAusLang()->kauNoDelimiterSet();
61
    }
62
}
63