DirDesc::canUse()   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 1
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_images\Sources;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Traits\TToString;
8
use kalanis\kw_paths\PathsException;
9
use kalanis\kw_paths\Stuff;
10
11
12
/**
13
 * Class DirDesc
14
 * Directory description
15
 * @package kalanis\kw_images\Sources
16
 */
17
class DirDesc extends AFiles
18
{
19
    use TToString;
20
21
    /**
22
     * @param string[] $path
23
     * @param bool $errorOnFail
24
     * @throws FilesException
25
     * @throws PathsException
26
     * @return string
27
     */
28 2
    public function get(array $path, bool $errorOnFail = false): string
29
    {
30
        try {
31 2
            return $this->toString(Stuff::arrayToPath($path), $this->lib->readFile($this->getPath($path)));
32 2
        } catch (FilesException $ex) {
33 2
            if (!$errorOnFail) {
34 2
                return '';
35
            }
36 1
            throw $ex;
37
        }
38
    }
39
40
    /**
41
     * @param string[] $path
42
     * @param string $content
43
     * @throws FilesException
44
     * @throws PathsException
45
     * @return bool
46
     */
47 2
    public function set(array $path, string $content): bool
48
    {
49 2
        return $this->lib->saveFile($this->getPath($path), $content);
50
    }
51
52
    /**
53
     * @param string[] $path
54
     * @throws FilesException
55
     * @throws PathsException
56
     * @return bool
57
     */
58 2
    public function remove(array $path): bool
59
    {
60 2
        return $this->lib->deleteFile($this->getPath($path));
61
    }
62
63
    /**
64
     * @param string[] $path
65
     * @throws FilesException
66
     * @throws PathsException
67
     * @return bool
68
     */
69 2
    public function canUse(array $path): bool
70
    {
71 2
        return $this->lib->isDir(array_merge($path, [$this->config->getDescDir()]));
72
    }
73
74 2
    public function getPath(array $path): array
75
    {
76 2
        return array_merge($path, [$this->config->getDescDir(), $this->config->getDescFile() . $this->config->getDescExt()]);
77
    }
78
}
79