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

CanDir   A

Complexity

Total Complexity 16

Size/Duplication

Total Lines 88
Duplicated Lines 0 %

Test Coverage

Coverage 95.12%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 40
dl 0
loc 88
ccs 39
cts 41
cp 0.9512
rs 10
c 1
b 0
f 0
wmc 16

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isWritable() 0 7 2
A noDirectoryDelimiterSet() 0 3 1
A isDir() 0 7 2
A isFile() 0 7 2
A created() 0 7 2
A exists() 0 7 2
A __construct() 0 4 1
A isReadable() 0 7 2
A size() 0 7 2
1
<?php
2
3
namespace kalanis\kw_files\Processing\Storage\Nodes;
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\Nodes
15
 * Process dirs via predefined api
16
 */
17
class CanDir extends ANodes
18
{
19
    /** @var IPassDirs */
20
    protected $storage = null;
21
22 8
    public function __construct(IPassDirs $storage, ?IFLTranslations $lang = null)
23
    {
24 8
        $this->storage = $storage;
25 8
        $this->setLang($lang);
26 8
    }
27
28 2
    public function exists(array $entry): bool
29
    {
30 2
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
31
        try {
32 2
            return $this->storage->exists($path);
33 1
        } catch (StorageException $ex) {
34 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
35
        }
36
    }
37
38 1
    public function isReadable(array $entry): bool
39
    {
40 1
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
41
        try {
42 1
            return $this->storage->isReadable($path);
43 1
        } catch (StorageException $ex) {
44 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
45
        }
46
    }
47
48 1
    public function isWritable(array $entry): bool
49
    {
50 1
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
51
        try {
52 1
            return $this->storage->isWritable($path);
53 1
        } catch (StorageException $ex) {
54 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
55
        }
56
    }
57
58 2
    public function isDir(array $entry): bool
59
    {
60 2
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
61
        try {
62 2
            return $this->storage->isDir($path);
63 1
        } catch (StorageException $ex) {
64 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
65
        }
66
    }
67
68 2
    public function isFile(array $entry): bool
69
    {
70 2
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
71
        try {
72 2
            return $this->storage->isFile($path);
73 1
        } catch (StorageException $ex) {
74 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
75
        }
76
    }
77
78 2
    public function size(array $entry): ?int
79
    {
80 2
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
81
        try {
82 2
            return $this->storage->size($path);
83 1
        } catch (StorageException $ex) {
84 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
85
        }
86
    }
87
88 2
    public function created(array $entry): ?int
89
    {
90 2
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
91
        try {
92 2
            return $this->storage->created($path);
93 1
        } catch (StorageException $ex) {
94 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
95
        }
96
    }
97
98
    /**
99
     * @return string
100
     * @codeCoverageIgnore only when path fails
101
     */
102
    protected function noDirectoryDelimiterSet(): string
103
    {
104
        return $this->getLang()->flNoDirectoryDelimiterSet();
105
    }
106
}
107