DirThumb::set()   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_images\Sources;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Traits\TToString;
8
use kalanis\kw_paths\PathsException;
9
10
11
/**
12
 * Class DirThumb
13
 * Directory thumbnail
14
 * @package kalanis\kw_images\Sources
15
 */
16
class DirThumb extends AFiles
17
{
18
    use TToString;
19
20
    /**
21
     * @param string[] $path
22
     * @throws FilesException
23
     * @throws PathsException
24
     * @return string|resource
25
     */
26 2
    public function get(array $path)
27
    {
28 2
        return $this->lib->readFile($this->getPath($path));
29
    }
30
31
    /**
32
     * @param string[] $path
33
     * @param string|resource $content
34
     * @throws FilesException
35
     * @throws PathsException
36
     * @return bool
37
     */
38 1
    public function set(array $path, $content): bool
39
    {
40 1
        return $this->lib->saveFile($this->getPath($path), $this->toString(implode(DIRECTORY_SEPARATOR, $path), $content));
41
    }
42
43
    /**
44
     * @param string[] $whichDir
45
     * @throws FilesException
46
     * @throws PathsException
47
     * @return bool
48
     */
49 2
    public function delete(array $whichDir): bool
50
    {
51 2
        $whatPath = $this->getPath($whichDir);
52 2
        return $this->dataRemove($whatPath, $this->getImLang()->imDirThumbCannotRemove());
53
    }
54
55 3
    public function getPath(array $path): array
56
    {
57 3
        return array_merge($path, [$this->config->getThumbDir(), $this->config->getDescFile() . $this->config->getThumbExt()]);
58
    }
59
}
60