Passed
Push — master ( 51c2a5...5c54bc )
by Petr
08:51
created

Basic   A

Complexity

Total Complexity 19

Size/Duplication

Total Lines 80
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

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