FileNode   A
last analyzed

Complexity

Total Complexity 11

Size/Duplication

Total Lines 84
Duplicated Lines 0 %

Test Coverage

Coverage 100%

Importance

Changes 0
Metric Value
wmc 11
eloc 24
dl 0
loc 84
ccs 28
cts 28
cp 1
rs 10
c 0
b 0
f 0

11 Methods

Rating   Name   Duplication   Size   Complexity  
A getSize() 0 3 1
A setData() 0 8 1
A isDir() 0 3 1
A getSubNodes() 0 3 1
A isReadable() 0 3 1
A isWritable() 0 3 1
A addSubNode() 0 4 1
A getType() 0 3 1
A isLink() 0 3 1
A isFile() 0 3 1
A getPath() 0 3 1
1
<?php
2
3
namespace kalanis\kw_tree\Essentials;
4
5
6
use kalanis\kw_files\Interfaces\ITypes;
7
8
9
/**
10
 * Class FileNode
11
 * @package kalanis\kw_tree\Essentials
12
 * File in directory (could be directory too)
13
 * Different, yet similar to SplFileInfo because it's possible to pack and unpack the whole thing without access to the real volume
14
 * Also represents more than one data source
15
 */
16
class FileNode
17
{
18
    /** @var string[] */
19
    protected array $path = [];
20
    protected string $type = ITypes::TYPE_UNKNOWN;
21
    protected int $size = 0;
22
    protected bool $readable = false;
23
    protected bool $writable = false;
24
    /** @var FileNode[] */
25
    protected array $subNodes = [];
26
27
    /**
28
     * @param string[] $path
29
     * @param int $size
30
     * @param string $type
31
     * @param bool $readable
32
     * @param bool $writable
33
     * @return $this
34
     */
35 10
    public function setData(array $path, int $size, string $type, bool $readable, bool $writable): self
36
    {
37 10
        $this->path = $path;
38 10
        $this->size = $size;
39 10
        $this->type = $type;
40 10
        $this->readable = $readable;
41 10
        $this->writable = $writable;
42 10
        return $this;
43
    }
44
45 9
    public function addSubNode(FileNode $node): self
46
    {
47 9
        $this->subNodes[] = $node;
48 9
        return $this;
49
    }
50
51
    /**
52
     * @return FileNode[]
53
     */
54 8
    public function getSubNodes(): array
55
    {
56 8
        return $this->subNodes;
57
    }
58
59
    /**
60
     * @return string[]
61
     */
62 10
    public function getPath(): array
63
    {
64 10
        return $this->path;
65
    }
66
67 2
    public function getSize(): int
68
    {
69 2
        return $this->size;
70
    }
71
72 6
    public function getType(): string
73
    {
74 6
        return $this->type;
75
    }
76
77 6
    public function isWritable(): bool
78
    {
79 6
        return $this->writable;
80
    }
81
82 6
    public function isReadable(): bool
83
    {
84 6
        return $this->readable;
85
    }
86
87 2
    public function isFile(): bool
88
    {
89 2
        return ITypes::TYPE_FILE == $this->type;
90
    }
91
92 2
    public function isDir(): bool
93
    {
94 2
        return ITypes::TYPE_DIR == $this->type;
95
    }
96
97 2
    public function isLink(): bool
98
    {
99 2
        return ITypes::TYPE_LINK == $this->type;
100
    }
101
}
102