ProcessNode   A
last analyzed

Complexity

Total Complexity 24

Size/Duplication

Total Lines 103
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 52
dl 0
loc 103
rs 10
c 1
b 0
f 0
ccs 53
cts 53
cp 1
wmc 24

9 Methods

Rating   Name   Duplication   Size   Complexity  
A size() 0 13 4
A isReadable() 0 3 1
A isWritable() 0 3 1
A isDir() 0 13 4
A exists() 0 9 3
A isFile() 0 13 4
A __construct() 0 5 1
A created() 0 13 5
A getLookupRecord() 0 3 1
1
<?php
2
3
namespace kalanis\kw_files_mapper\Processing\Mapper;
4
5
6
use kalanis\kw_files\FilesException;
7
use kalanis\kw_files\Interfaces\IFLTranslations;
8
use kalanis\kw_files\Interfaces\IProcessNodes;
9
use kalanis\kw_files\Traits\TLang;
10
use kalanis\kw_files_mapper\Support\Process;
11
use kalanis\kw_mapper\MapperException;
12
use kalanis\kw_mapper\Records\ARecord;
13
14
15
/**
16
 * Class ProcessNode
17
 * @package kalanis\kw_files_mapper\Processing\Mapper
18
 * Process nodes in basic ways
19
 */
20
class ProcessNode implements IProcessNodes
21
{
22
    use TEntryLookup;
23
    use TLang;
24
25
    protected ARecord $record;
26
27 9
    public function __construct(ARecord $record, ?Process\Translate $translate = null, ?IFLTranslations $lang = null)
28
    {
29 9
        $this->setFlLang($lang);
30 9
        $this->record = $record;
31 9
        $this->setTranslation($translate);
32 9
    }
33
34 3
    public function exists(array $entry): bool
35
    {
36 3
        if (empty($entry)) {
37 1
            return true;
38
        }
39
        try {
40 2
            return !is_null($this->getEntry($entry));
41 1
        } catch (MapperException $ex) {
42 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
43
        }
44
    }
45
46 1
    public function isReadable(array $entry): bool
47
    {
48 1
        return true;
49
    }
50
51 1
    public function isWritable(array $entry): bool
52
    {
53 1
        return true;
54
    }
55
56 3
    public function isDir(array $entry): bool
57
    {
58 3
        if (empty($entry)) {
59 1
            return true;
60
        }
61
        try {
62 2
            $entry = $this->getEntry($entry);
63 1
            if (is_null($entry)) {
64 1
                return false;
65
            }
66 1
            return static::STORAGE_NODE_KEY === strval($entry->__get($this->getTranslation()->getContentKey()));
67 1
        } catch (MapperException $ex) {
68 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
69
        }
70
    }
71
72 3
    public function isFile(array $entry): bool
73
    {
74 3
        if (empty($entry)) {
75 1
            return false;
76
        }
77
        try {
78 2
            $entry = $this->getEntry($entry);
79 1
            if (is_null($entry)) {
80 1
                return false;
81
            }
82 1
            return static::STORAGE_NODE_KEY !== strval($entry->__get($this->getTranslation()->getContentKey()));
83 1
        } catch (MapperException $ex) {
84 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
85
        }
86
    }
87
88 3
    public function size(array $entry): ?int
89
    {
90 3
        if (empty($entry)) {
91 1
            return null;
92
        }
93
        try {
94 2
            $entry = $this->getEntry($entry);
95 1
            if (is_null($entry)) {
96 1
                return null;
97
            }
98 1
            return strlen(strval($entry->__get($this->getTranslation()->getContentKey())));
99 1
        } catch (MapperException $ex) {
100 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
101
        }
102
    }
103
104 3
    public function created(array $entry): ?int
105
    {
106 3
        if (empty($entry) || is_null($this->getTranslation()->getCreatedKey())) {
107 1
            return null;
108
        }
109
        try {
110 2
            $entry = $this->getEntry($entry);
111 1
            if (is_null($entry)) {
112 1
                return null;
113
            }
114 1
            return intval(strval($entry->__get($this->getTranslation()->getCreatedKey())));
115 1
        } catch (MapperException $ex) {
116 1
            throw new FilesException($ex->getMessage(), $ex->getCode(), $ex);
117
        }
118
    }
119
120 1
    protected function getLookupRecord(): ARecord
121
    {
122 1
        return clone $this->record;
123
    }
124
}
125