Passed
Branch master (7a2f1a)
by Petr
03:10
created

ExtendDir::getWebRootDir()   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3
Code Lines 1

Duplication

Lines 0
Ratio 0 %

Code Coverage

Tests 2
CRAP Score 1

Importance

Changes 1
Bugs 0 Features 0
Metric Value
eloc 1
c 1
b 0
f 0
dl 0
loc 3
ccs 2
cts 2
cp 1
rs 10
cc 1
nc 1
nop 0
crap 1
1
<?php
2
3
namespace kalanis\kw_paths\Extras;
4
5
6
use Error;
7
use kalanis\kw_paths\Interfaces\IPATranslations;
8
use kalanis\kw_paths\PathsException;
9
use kalanis\kw_paths\Stuff;
10
use kalanis\kw_paths\Translations;
11
12
13
/**
14
 * Class ExtendDir
15
 * low-level work with extended dirs - which contains other params than just files and sub dirs
16
 * @deprecated since 2023-01-01 instead use
17
 * @see \kalanis\kw_files\Extended\Processor
18
 */
19
class ExtendDir
20
{
21
    use TRemoveCycle;
0 ignored issues
show
Deprecated Code introduced by
The trait kalanis\kw_paths\Extras\TRemoveCycle has been deprecated: since 2023-01-01 use instead ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

21
    use /** @scrutinizer ignore-deprecated */ TRemoveCycle;

This trait has been deprecated. The supplier of the trait has supplied an explanatory message.

The explanatory message should give you some clue as to whether and when the trait will be removed and what other trait to use instead.

Loading history...
22
23
    /** @var string */
24
    protected $webRootDir = ''; # system path to web root dir
25
    /** @var string */
26
    protected $descDir = '.txt'; # description dir
27
    /** @var string */
28
    protected $descFile = 'index'; # description index filename
29
    /** @var string */
30
    protected $descExt = '.dsc'; # description file's extension - add to original name
31
    /** @var string */
32
    protected $thumbDir = '.tmb'; # thumbnail dir
33
    /** @var IPATranslations */
34
    protected $lang = null;
35
36 9
    public function __construct(string $webRootDir, ?string $descDir = null, ?string $descFile = null, ?string $descExt = null, ?string $thumbDir = null, ?IPATranslations $lang = null)
37
    {
38 9
        $this->webRootDir = $webRootDir;
39 9
        $this->descDir = $descDir ?: $this->descDir;
40 9
        $this->descFile = $descFile ?: $this->descFile;
41 9
        $this->descExt = $descExt ?: $this->descExt;
42 9
        $this->thumbDir = $thumbDir ?: $this->thumbDir;
43 9
        $this->lang = $lang ?: new Translations();
44 9
    }
45
46 9
    public function getWebRootDir(): string
47
    {
48 9
        return $this->webRootDir;
49
    }
50
51 3
    public function getDescDir(): string
52
    {
53 3
        return $this->descDir;
54
    }
55
56 1
    public function getDescFile(): string
57
    {
58 1
        return $this->descFile;
59
    }
60
61 1
    public function getDescExt(): string
62
    {
63 1
        return $this->descExt;
64
    }
65
66 3
    public function getThumbDir(): string
67
    {
68 3
        return $this->thumbDir;
69
    }
70
71
    /**
72
     * @param string $path the path inside the web root dir
73
     * @param string $name
74
     * @param bool $makeExtra
75
     * @throws PathsException
76
     * @return bool
77
     * @deprecated
78
     * @see \kalanis\kw_files\Extended\Processor::createDir
79
     */
80 4
    public function createDir(string $path, string $name, bool $makeExtra = false): bool
81
    {
82
        try {
83 4
            $target = empty($path) ? '' : Stuff::removeEndingSlash($path) . DIRECTORY_SEPARATOR;
84 4
            $targetPath = $target . $name ;
85 4
            return mkdir($this->webRootDir . $targetPath)
86 4
                && ( $makeExtra ? $this->makeExtended($targetPath) : true );
0 ignored issues
show
Deprecated Code introduced by
The function kalanis\kw_paths\Extras\ExtendDir::makeExtended() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

86
                && ( $makeExtra ? /** @scrutinizer ignore-deprecated */ $this->makeExtended($targetPath) : true );
Loading history...
87
            // @codeCoverageIgnoreStart
88
        } catch (Error $ex) {
89
            throw new PathsException($ex->getMessage(), $ex->getCode(), $ex);
90
            // @codeCoverageIgnoreEnd
91
        }
92
    }
93
94
    /**
95
     * Make dir with extended properties
96
     * @param string $path
97
     * @throws PathsException
98
     * @return bool
99
     * @deprecated
100
     * @see \kalanis\kw_files\Extended\Processor::makeExtended
101
     */
102 3
    public function makeExtended(string $path): bool
103
    {
104 3
        $current = Stuff::removeEndingSlash($path) . DIRECTORY_SEPARATOR;
105 3
        $descDir = $this->webRootDir . $current . $this->descDir;
106 3
        $thumbDir = $this->webRootDir . $current . $this->thumbDir;
107 3
        if (is_dir($descDir) && is_dir($thumbDir)) { // already exists
108 1
            return true;
109
        }
110 3
        if ((!@mkdir($descDir)) && (!is_dir($descDir))) {
111 1
            throw new PathsException($this->lang->paCannotCreateDescDir());
112
        }
113 2
        if ((!@mkdir($thumbDir)) && (!is_dir($thumbDir))) {
114 1
            throw new PathsException($this->lang->paCannotCreateThumbDir());
115
        }
116 1
        return true;
117
    }
118
119
    /**
120
     * @param string $path
121
     * @throws PathsException
122
     * @return bool
123
     * @deprecated
124
     * @see \kalanis\kw_files\Extended\Processor::removeExtended
125
     */
126 1
    public function removeExtended(string $path): bool
127
    {
128 1
        $current = Stuff::removeEndingSlash($path) . DIRECTORY_SEPARATOR;
129 1
        $descDir = $this->webRootDir . $current . $this->descDir;
130 1
        $thumbDir = $this->webRootDir . $current . $this->thumbDir;
131
132 1
        $this->isWritable($descDir);
0 ignored issues
show
Deprecated Code introduced by
The function kalanis\kw_paths\Extras\ExtendDir::isWritable() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

132
        /** @scrutinizer ignore-deprecated */ $this->isWritable($descDir);
Loading history...
133 1
        $this->isWritable($thumbDir);
0 ignored issues
show
Deprecated Code introduced by
The function kalanis\kw_paths\Extras\ExtendDir::isWritable() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

133
        /** @scrutinizer ignore-deprecated */ $this->isWritable($thumbDir);
Loading history...
134 1
        $this->removeCycle($descDir);
0 ignored issues
show
Deprecated Code introduced by
The function kalanis\kw_paths\Extras\ExtendDir::removeCycle() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

134
        /** @scrutinizer ignore-deprecated */ $this->removeCycle($descDir);
Loading history...
135 1
        $this->removeCycle($thumbDir);
0 ignored issues
show
Deprecated Code introduced by
The function kalanis\kw_paths\Extras\ExtendDir::removeCycle() has been deprecated. ( Ignorable by Annotation )

If this is a false-positive, you can also ignore this issue in your code via the ignore-deprecated  annotation

135
        /** @scrutinizer ignore-deprecated */ $this->removeCycle($thumbDir);
Loading history...
136 1
        return true;
137
    }
138
139
    /**
140
     * @param string $path
141
     * @throws PathsException
142
     * @return bool
143
     * @deprecated
144
     * @see \kalanis\kw_files\Interfaces\IProcessNodes::isReadable
145
     */
146 2
    public function isReadable(string $path): bool
147
    {
148 2
        if (is_dir($path) && is_readable($path)) {
149 1
            return true;
150
        }
151 2
        throw new PathsException($this->lang->paCannotAccessWantedDir());
152
    }
153
154
    /**
155
     * @param string $path
156
     * @throws PathsException
157
     * @return bool
158
     * @deprecated
159
     * @see \kalanis\kw_files\Interfaces\IProcessNodes::isWritable
160
     */
161 3
    public function isWritable(string $path): bool
162
    {
163 3
        if (is_dir($path) && is_writable($path)) {
164 2
            return true;
165
        }
166 2
        throw new PathsException($this->lang->paCannotWriteIntoDir());
167
    }
168
169
    /**
170
     * @param string $path
171
     * @return bool
172
     * @deprecated
173
     * @see \kalanis\kw_files\Interfaces\IProcessNodes::isFile
174
     */
175 1
    public function isFile(string $path): bool
176
    {
177 1
        return is_file($path);
178
    }
179
180
    /**
181
     * @param string $path
182
     * @return bool
183
     * @deprecated
184
     * @see \kalanis\kw_files\Interfaces\IProcessNodes::isDir
185
     */
186 1
    public function isDir(string $path): bool
187
    {
188 1
        return is_dir($path);
189
    }
190
}
191