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

ProcessNode::noDirectoryDelimiterSet()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 0
CRAP Score 2

Importance

Changes 0
Metric Value
cc 1
eloc 1
nc 1
nop 0
dl 0
loc 3
ccs 0
cts 2
cp 0
crap 2
rs 10
c 0
b 0
f 0
1
<?php
2
3
namespace kalanis\kw_files\Processing\Volume;
4
5
6
use kalanis\kw_files\Interfaces\IFLTranslations;
7
use kalanis\kw_files\Interfaces\IProcessNodes;
8
use kalanis\kw_files\Processing\TPath;
9
use kalanis\kw_files\Translations;
10
use kalanis\kw_paths\Extras\TPathTransform;
11
use kalanis\kw_paths\PathsException;
12
13
14
/**
15
 * Class ProcessNode
16
 * @package kalanis\kw_files\Processing\Volume
17
 * Process nodes in basic ways
18
 */
19
class ProcessNode implements IProcessNodes
20
{
21
    use TPath;
22
    use TPathTransform;
23
24
    /** @var IFLTranslations */
25
    protected $lang = null;
26
27 5
    public function __construct(string $path = '', ?IFLTranslations $lang = null)
28
    {
29 5
        $this->setPath($path);
30 5
        $this->lang = $lang ?? new Translations();
31 5
    }
32
33 1
    public function exists(array $entry): bool
34
    {
35 1
        return @file_exists($this->fullPath($entry));
36
    }
37
38 1
    public function isReadable(array $entry): bool
39
    {
40 1
        return @is_readable($this->fullPath($entry));
41
    }
42
43 1
    public function isWritable(array $entry): bool
44
    {
45 1
        return @is_writable($this->fullPath($entry));
46
    }
47
48 1
    public function isDir(array $entry): bool
49
    {
50 1
        return @is_dir($this->fullPath($entry));
51
    }
52
53 1
    public function isFile(array $entry): bool
54
    {
55 1
        return @is_file($this->fullPath($entry));
56
    }
57
58 1
    public function size(array $entry): ?int
59
    {
60 1
        $path = $this->fullPath($entry);
61 1
        $size = @filesize($path);
62 1
        return (false === $size) ? null : $size;
63
    }
64
65 1
    public function created(array $entry): ?int
66
    {
67 1
        $path = $this->fullPath($entry);
68 1
        $created = @filemtime($path);
69 1
        return (false === $created) ? null : $created;
70
    }
71
72
    /**
73
     * @param array<string> $path
74
     * @throws PathsException
75
     * @return string
76
     */
77 1
    protected function fullPath(array $path): string
78
    {
79 1
        return $this->getPath() . DIRECTORY_SEPARATOR . $this->compactName($path);
80
    }
81
82
    /**
83
     * @return string
84
     * @codeCoverageIgnore only when path fails
85
     */
86
    protected function noDirectoryDelimiterSet(): string
87
    {
88
        return $this->lang->flNoDirectoryDelimiterSet();
89
    }
90
}
91