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

Volume::noDirectoryDelimiterSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
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_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