Passed
Push — master ( f1fb72...be1df6 )
by Petr
08:10
created

Volume   A

Complexity

Total Complexity 7

Size/Duplication

Total Lines 48
Duplicated Lines 0 %

Test Coverage

Coverage 73.68%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 19
dl 0
loc 48
ccs 14
cts 19
cp 0.7368
rs 10
c 1
b 0
f 0
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
    /** @var string */
23
    protected $startDirectory = '';
24
25 14
    public function __construct(string $where, ?IKAusTranslations $ausLang = null)
26
    {
27 14
        $this->startDirectory = $where;
28 14
        $this->setAusLang($ausLang);
29 14
    }
30
31 2
    protected function open(array $path): string
32
    {
33
        try {
34 2
            $pt = $this->startDirectory . Stuff::arrayToPath($path);
35 2
            $content = @file_get_contents($pt);
36 2
            if (false === $content) {
37 1
                throw new AuthSourcesException($this->getAusLang()->kauPassFileNotFound($pt));
38
            }
39 1
            return strval($content);
40
            // @codeCoverageIgnoreStart
41 1
        } catch (PathsException $ex) {
42
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
43
        }
44
        // @codeCoverageIgnoreEnd
45
    }
46
47 2
    protected function save(array $path, string $content): bool
48
    {
49
        try {
50 2
            $pt = $this->startDirectory . Stuff::arrayToPath($path);
51 2
            return boolval(@file_put_contents($pt, $content));
52
            // @codeCoverageIgnoreStart
53
        } catch (PathsException $ex) {
54
            throw new AuthSourcesException($ex->getMessage(), $ex->getCode(), $ex);
55
        }
56
        // @codeCoverageIgnoreEnd
57
    }
58
59
    /**
60
     * @return string
61
     * @codeCoverageIgnore translation
62
     */
63
    protected function noDirectoryDelimiterSet(): string
64
    {
65
        return $this->getAusLang()->kauNoDelimiterSet();
66
    }
67
}
68