Passed
Push — master ( cb2d88...e8a992 )
by Petr
08:25
created

Basic::__construct()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 4
Code Lines 2

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 3
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
cc 1
eloc 2
c 1
b 0
f 0
nc 1
nop 2
dl 0
loc 4
ccs 3
cts 3
cp 1
crap 1
rs 10
1
<?php
2
3
namespace kalanis\kw_files\Processing\Storage\Files;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Interfaces\IFLTranslations;
8
use kalanis\kw_storage\Interfaces\IStorage;
9
use kalanis\kw_storage\StorageException;
10
11
12
/**
13
 * Class Basic
14
 * @package kalanis\kw_files\Processing\Storage\Files
15
 * Process files via lookup
16
 */
17
class Basic extends AFiles
18
{
19 18
    public function __construct(IStorage $storage, ?IFLTranslations $lang = null)
20
    {
21 18
        $this->storage = $storage;
22 18
        $this->setLang($lang);
23 18
    }
24
25 3
    public function copyFile(array $source, array $dest): bool
26
    {
27 3
        $src = $this->getStorageSeparator() . $this->filledName($this->compactName($source, $this->getStorageSeparator()));
28 3
        $dst = $this->getStorageSeparator() . $this->filledName($this->compactName($dest, $this->getStorageSeparator()));
29
        try {
30 3
            return $this->storage->write($dst, $this->storage->read($src));
31 2
        } catch (StorageException $ex) {
32 2
            throw new FilesException($this->getLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex);
33
        }
34
    }
35
36 2
    public function moveFile(array $source, array $dest): bool
37
    {
38 2
        $v1 = $this->copyFile($source, $dest);
39 1
        $v2 = $this->deleteFile($source);
40 1
        return $v1 && $v2;
41
    }
42
43
    /**
44
     * @return string
45
     * @codeCoverageIgnore only when path fails
46
     */
47
    protected function noDirectoryDelimiterSet(): string
48
    {
49
        return $this->getLang()->flNoDirectoryDelimiterSet();
50
    }
51
}
52