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

CanDir   A

Complexity

Total Complexity 6

Size/Duplication

Total Lines 40
Duplicated Lines 0 %

Test Coverage

Coverage 88.89%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 40
ccs 16
cts 18
cp 0.8889
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A noDirectoryDelimiterSet() 0 3 1
A moveFile() 0 8 2
A __construct() 0 4 1
A copyFile() 0 8 2
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\IPassDirs;
9
use kalanis\kw_storage\StorageException;
10
11
12
/**
13
 * Class CanDir
14
 * @package kalanis\kw_files\Processing\Storage\Files
15
 * Process files via predefined api
16
 */
17
class CanDir extends AFiles
18
{
19
    /** @var IPassDirs */
20
    protected $storage = null;
21
22 9
    public function __construct(IPassDirs $storage, ?IFLTranslations $lang = null)
23
    {
24 9
        $this->storage = $storage;
25 9
        $this->setLang($lang);
26 9
    }
27
28 2
    public function copyFile(array $source, array $dest): bool
29
    {
30 2
        $src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator());
31 2
        $dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator());
32
        try {
33 2
            return $this->storage->copy($src, $dst);
34 1
        } catch (StorageException $ex) {
35 1
            throw new FilesException($this->getLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex);
36
        }
37
    }
38
39 2
    public function moveFile(array $source, array $dest): bool
40
    {
41 2
        $src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator());
42 2
        $dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator());
43
        try {
44 2
            return $this->storage->move($src, $dst);
45 1
        } catch (StorageException $ex) {
46 1
            throw new FilesException($this->getLang()->flCannotMoveFile($src, $dst), $ex->getCode(), $ex);
47
        }
48
    }
49
50
    /**
51
     * @return string
52
     * @codeCoverageIgnore only when path fails
53
     */
54
    protected function noDirectoryDelimiterSet(): string
55
    {
56
        return $this->getLang()->flNoDirectoryDelimiterSet();
57
    }
58
}
59