AStorage::write()   A
last analyzed

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 1
nc 1
nop 2
dl 0
loc 3
ccs 2
cts 2
cp 1
crap 1
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\IFile;
8
use kalanis\kw_auth_sources\Traits\TLines;
9
10
11
/**
12
 * Class AStorage
13
 * @package kalanis\kw_auth_sources\Sources\Files\Files
14
 * Storages of files with data for authentication
15
 */
16
abstract class AStorage
17
{
18
    use TLines;
19
20
    /**
21
     * @param string[] $path
22
     * @throws AuthSourcesException
23
     * @return array<int, array<int, string>>
24
     */
25 33
    public function read(array $path): array
26
    {
27 33
        $lines = explode(IFile::CRLF, $this->open($path));
28 19
        return array_map([$this, 'explosion'], array_filter(array_map('trim', $lines), [$this, 'filterEmptyLines']));
29
    }
30
31
    /**
32
     * @param string[] $path
33
     * @throws AuthSourcesException
34
     * @return string
35
     */
36
    abstract protected function open(array $path): string;
37
38
    /**
39
     * @param string[] $path
40
     * @param array<int, array<int, string|int>> $lines
41
     * @throws AuthSourcesException
42
     * @return bool
43
     */
44 12
    public function write(array $path, array $lines): bool
45
    {
46 12
        return $this->save($path, strval(implode(IFile::CRLF, array_map([$this, 'implosion'], $lines)) . IFile::CRLF));
47
    }
48
49
    /**
50
     * @param string[] $path
51
     * @param string $data
52
     * @throws AuthSourcesException
53
     * @return bool
54
     */
55
    abstract protected function save(array $path, string $data): bool;
56
}
57