Passed
Push — master ( 399339...9c419c )
by Petr
08:15
created

Basic   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 94.59%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 34
c 1
b 0
f 0
dl 0
loc 80
ccs 35
cts 37
cp 0.9459
rs 10
wmc 19

9 Methods

Rating   Name   Duplication   Size   Complexity  
A isDir() 0 8 4
A isFile() 0 8 4
A isReadable() 0 3 1
A exists() 0 8 3
A noDirectoryDelimiterSet() 0 3 1
A size() 0 10 3
A isWritable() 0 3 1
A __construct() 0 4 1
A created() 0 3 1
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_files\Traits\TToString;
9
use kalanis\kw_storage\Interfaces\IStorage;
10
use kalanis\kw_storage\StorageException;
11
12
13
/**
14
 * Class Basic
15
 * @package kalanis\kw_files\Processing\Storage\Nodes
16
 * Process dirs via lookup
17
 */
18
class Basic extends ANodes
19
{
20
    use TToString;
21
22
    protected IStorage $storage;
23
24 13
    public function __construct(IStorage $storage, ?IFLTranslations $lang = null)
25
    {
26 13
        $this->storage = $storage;
27 13
        $this->setFlLang($lang);
28 13
    }
29
30 8
    public function exists(array $entry): bool
31
    {
32 8
        $path = $this->compactName($entry, $this->getStorageSeparator());
33 8
        $path = empty($entry) ? $path : $this->getStorageSeparator() . $path;
34
        try {
35 8
            return $this->storage->exists($path);
36 1
        } catch (StorageException $ex) {
37 1
            throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex);
38
        }
39
    }
40
41 1
    public function isReadable(array $entry): bool
42
    {
43 1
        return true;
44
    }
45
46 1
    public function isWritable(array $entry): bool
47
    {
48 1
        return true;
49
    }
50
51 8
    public function isDir(array $entry): bool
52
    {
53 8
        $path = $this->compactName($entry, $this->getStorageSeparator());
54 8
        $path = empty($entry) ? $path : $this->getStorageSeparator() . $path;
55
        try {
56 8
            return $this->storage->exists($path) && static::STORAGE_NODE_KEY === $this->toString($path, $this->storage->read($path));
57 1
        } catch (StorageException $ex) {
58 1
            throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex);
59
        }
60
    }
61
62 4
    public function isFile(array $entry): bool
63
    {
64 4
        $path = $this->compactName($entry, $this->getStorageSeparator());
65 4
        $path = empty($entry) ? $path : $this->getStorageSeparator() . $path;
66
        try {
67 4
            return $this->storage->exists($path) && static::STORAGE_NODE_KEY !== $this->toString($path, $this->storage->read($path));
68 1
        } catch (StorageException $ex) {
69 1
            throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex);
70
        }
71
    }
72
73 3
    public function size(array $entry): ?int
74
    {
75 3
        $path = $this->getStorageSeparator() . $this->compactName($entry, $this->getStorageSeparator());
76
        try {
77 3
            if (!$this->storage->exists($path)) {
78 2
                return null;
79
            }
80 1
            return strlen($this->storage->read($path));
81 1
        } catch (StorageException $ex) {
82 1
            throw new FilesException($this->getFlLang()->flCannotProcessNode($path), $ex->getCode(), $ex);
83
        }
84
    }
85
86 2
    public function created(array $entry): ?int
87
    {
88 2
        return null;
89
    }
90
91
    /**
92
     * @return string
93
     * @codeCoverageIgnore only when path fails
94
     */
95
    protected function noDirectoryDelimiterSet(): string
96
    {
97
        return $this->getFlLang()->flNoDirectoryDelimiterSet();
98
    }
99
}
100