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

Basic   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 33
Duplicated Lines 0 %

Test Coverage

Coverage 87.5%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 13
dl 0
loc 33
ccs 14
cts 16
cp 0.875
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A copyFile() 0 8 2
A moveFile() 0 5 2
A noDirectoryDelimiterSet() 0 3 1
A __construct() 0 4 1
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