Volume   A
last analyzed

Complexity

Total Complexity 7

Size/Duplication

Total Lines 47
Duplicated Lines 0 %

Test Coverage

Coverage 73.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
c 1
b 0
f 0
dl 0
loc 47
ccs 14
cts 19
cp 0.7368
rs 10
wmc 7

4 Methods

Rating   Name   Duplication   Size   Complexity  
A __construct() 0 4 1
A save() 0 8 2
A open() 0 12 3
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_paths\PathsException;
10
use kalanis\kw_paths\Stuff;
11
12
13
/**
14
 * Class Volume
15
 * @package kalanis\kw_auth_sources\Sources\Files\Volume
16
 * Processing files on local volume
17
 */
18
class Volume extends AStorage
19
{
20
    use TLang;
21
22
    protected string $startDirectory = '';
23
24 14
    public function __construct(string $where, ?IKAusTranslations $ausLang = null)
25
    {
26 14
        $this->startDirectory = $where;
27 14
        $this->setAusLang($ausLang);
28 14
    }
29
30 2
    protected function open(array $path): string
31
    {
32
        try {
33 2
            $pt = $this->startDirectory . Stuff::arrayToPath($path);
34 2
            $content = @file_get_contents($pt);
35 2
            if (false === $content) {
36 1
                throw new AuthSourcesException($this->getAusLang()->kauPassFileNotFound($pt));
37
            }
38 1
            return strval($content);
39
            // @codeCoverageIgnoreStart
40 1
        } catch (PathsException $ex) {
41
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
42
        }
43
        // @codeCoverageIgnoreEnd
44
    }
45
46 2
    protected function save(array $path, string $content): bool
47
    {
48
        try {
49 2
            $pt = $this->startDirectory . Stuff::arrayToPath($path);
50 2
            return boolval(@file_put_contents($pt, $content));
51
            // @codeCoverageIgnoreStart
52
        } catch (PathsException $ex) {
53
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
54
        }
55
        // @codeCoverageIgnoreEnd
56
    }
57
58
    /**
59
     * @return string
60
     * @codeCoverageIgnore translation
61
     */
62
    protected function noDirectoryDelimiterSet(): string
63
    {
64
        return $this->getAusLang()->kauNoDelimiterSet();
65
    }
66
}
67