CanDir   A
last analyzed

Complexity

Total Complexity 6

Size/Duplication

Total Lines 39
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 17
dl 0
loc 39
ccs 15
cts 15
cp 1
rs 10
c 1
b 0
f 0
wmc 6

4 Methods

Rating   Name   Duplication   Size   Complexity  
A moveFile() 0 8 2
A __construct() 0 4 1
A copyFile() 0 8 2
A noDirectoryDelimiterSet() 0 3 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\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
    protected IPassDirs $passStorage;
20
21 13
    public function __construct(IPassDirs $storage, ?IFLTranslations $lang = null)
22
    {
23 13
        parent::__construct($storage, $lang);
24 13
        $this->passStorage = $storage;
25
    }
26
27 2
    public function copyFile(array $source, array $dest): bool
28
    {
29 2
        $src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator());
30 2
        $dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator());
31
        try {
32 2
            return $this->passStorage->copy($src, $dst);
33 1
        } catch (StorageException $ex) {
34 1
            throw new FilesException($this->getFlLang()->flCannotCopyFile($src, $dst), $ex->getCode(), $ex);
35
        }
36
    }
37
38 2
    public function moveFile(array $source, array $dest): bool
39
    {
40 2
        $src = $this->getStorageSeparator() . $this->compactName($source, $this->getStorageSeparator());
41 2
        $dst = $this->getStorageSeparator() . $this->compactName($dest, $this->getStorageSeparator());
42
        try {
43 2
            return $this->passStorage->move($src, $dst);
44 1
        } catch (StorageException $ex) {
45 1
            throw new FilesException($this->getFlLang()->flCannotMoveFile($src, $dst), $ex->getCode(), $ex);
46
        }
47
    }
48
49
    /**
50
     * @return string
51
     * @codeCoverageIgnore only when path fails
52
     */
53
    protected function noDirectoryDelimiterSet(): string
54
    {
55
        return $this->getFlLang()->flNoDirectoryDelimiterSet();
56
    }
57
}
58