This project does not seem to handle request data directly as such no vulnerable execution paths were found.
include
, or for example
via PHP's auto-loading mechanism.
These results are based on our legacy PHP analysis, consider migrating to our new PHP analysis engine instead. Learn more
1 | <?php |
||
2 | /******************************************************************* |
||
3 | * Created by: Marko Kungla @ OkramLabs on Aug 6, 2012 - 10:02:48 |
||
4 | * Contact: [email protected] - https://okramlabs.com |
||
5 | * @copyright 2015 OkramLabs - https://okramlabs.com |
||
6 | * @license MIT |
||
7 | * |
||
8 | * Package name:libhowi-filesystem |
||
9 | * @category HOWI3 |
||
10 | * @package libhowi |
||
11 | * @subpackage filesystem |
||
12 | * |
||
13 | * Lang: PHP |
||
14 | * Encoding: UTF-8 |
||
15 | * File: TraitForSharedMethods.inc |
||
16 | * @link https:// |
||
17 | ******************************************************************** |
||
18 | * Contributors: |
||
19 | * @author Marko Kungla <[email protected]> |
||
20 | * Github: https://github.com/mkungla |
||
21 | ******************************************************************** |
||
22 | * Comments: |
||
23 | */ |
||
24 | namespace HOWI3\libhowi\Filesystem\php7; |
||
25 | |||
26 | use \RecursiveDirectoryIterator; |
||
27 | use \RecursiveIteratorIterator; |
||
28 | use \DateTime; |
||
29 | |||
30 | View Code Duplication | trait TraitForSharedMethods |
|
0 ignored issues
–
show
|
|||
31 | { |
||
32 | |||
33 | /** |
||
34 | * |
||
35 | * {@inheritDoc} |
||
36 | * |
||
37 | */ |
||
38 | 241 | protected function setCwd($path = false, $validate_dir_name = false) |
|
39 | { |
||
40 | 241 | if (empty($path)) |
|
41 | 241 | $current_working_directory = $this->getCwd(); |
|
42 | else |
||
43 | 8 | $current_working_directory = $this->makeAbsolute($path); |
|
44 | |||
45 | 241 | if (! empty($validate_dir_name) && (basename($current_working_directory) !== $validate_dir_name)) |
|
46 | return false; |
||
47 | |||
48 | 241 | if (! is_dir($current_working_directory) || ! is_readable($current_working_directory) || |
|
49 | 241 | ! chdir($current_working_directory)) { |
|
50 | 4 | $this->alert(200, false, $current_working_directory); |
|
0 ignored issues
–
show
It seems like
alert() must be provided by classes using this trait. How about adding it as abstract method to this trait?
This check looks for methods that are used by a trait but not required by it. To illustrate, let’s look at the following code example trait Idable {
public function equalIds(Idable $other) {
return $this->getId() === $other->getId();
}
}
The trait Adding the ![]() |
|||
51 | 4 | return false; |
|
52 | } |
||
53 | 241 | $this->cwd = $current_working_directory; |
|
0 ignored issues
–
show
The property
cwd does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
54 | 241 | return true; |
|
55 | } |
||
56 | |||
57 | /** |
||
58 | * |
||
59 | * {@inheritDoc} |
||
60 | * |
||
61 | */ |
||
62 | 241 | public function getCwd() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
63 | { |
||
64 | 241 | if (empty($this->cwd)) |
|
65 | 241 | $this->cwd = getcwd(); |
|
66 | |||
67 | 241 | return $this->cwd; |
|
68 | } |
||
69 | |||
70 | /** |
||
71 | * |
||
72 | * {@inheritDoc} |
||
73 | * |
||
74 | */ |
||
75 | 7 | public function getSize($convert = false, $filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
76 | { |
||
77 | 7 | $filename = ! empty($filename) ? $this->makeAbsolute($filename) : false; |
|
78 | 7 | $bytestotal = empty($filename) ? ((method_exists(get_parent_class($this), 'getSize')) ? parent::getSize() : false) : filesize( |
|
79 | $filename); |
||
80 | |||
81 | 7 | if (! $this->isDir($filename) && empty($convert)) |
|
0 ignored issues
–
show
It seems like
$filename defined by !empty($filename) ? $thi...lute($filename) : false on line 77 can also be of type string ; however, HOWI3\libhowi\Filesystem...rSharedMethods::isDir() does only seem to accept boolean , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
82 | 7 | return $bytestotal; |
|
83 | |||
84 | $suffixes = array( |
||
85 | 5 | 'B', |
|
86 | 'kB', |
||
87 | 'MB', |
||
88 | 'GB', |
||
89 | 'TB', |
||
90 | 'PB', |
||
91 | 'EB', |
||
92 | 'ZB', |
||
93 | 'YB' |
||
94 | ); |
||
95 | 5 | if ($this->isDir($filename)) { |
|
0 ignored issues
–
show
It seems like
$filename defined by !empty($filename) ? $thi...lute($filename) : false on line 77 can also be of type string ; however, HOWI3\libhowi\Filesystem...rSharedMethods::isDir() does only seem to accept boolean , maybe add an additional type check?
If a method or function can return multiple different values and unless you are sure that you only can receive a single value in this context, we recommend to add an additional type check: /**
* @return array|string
*/
function returnsDifferentValues($x) {
if ($x) {
return 'foo';
}
return array();
}
$x = returnsDifferentValues($y);
if (is_array($x)) {
// $x is an array.
}
If this a common case that PHP Analyzer should handle natively, please let us know by opening an issue. ![]() |
|||
96 | 3 | $path = ((method_exists(get_class($this), 'getPathname')) ? $this->getPathname() : $filename); |
|
97 | 3 | if ($path === '/home/nitrotrigger/tmp/libhowi-filesystem/log/phpunit_test.log') |
|
98 | die('ss'); |
||
99 | |||
100 | 3 | foreach (new RecursiveIteratorIterator( |
|
101 | 3 | new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)) as $object) { |
|
102 | 3 | $bytestotal += $object->getSize(); |
|
103 | } |
||
104 | 3 | if (! $convert) |
|
105 | 3 | return $bytestotal; |
|
106 | } |
||
107 | 4 | $base = log($bytestotal, 1024); |
|
108 | |||
109 | $result = [ |
||
110 | 4 | 0, |
|
111 | 'B' |
||
112 | ]; |
||
113 | 4 | if ($bytestotal > 0) { |
|
114 | |||
115 | $result = array( |
||
116 | 4 | round(pow(1024, $base - floor($base)), 2), |
|
117 | 4 | $suffixes[floor($base)] |
|
118 | ); |
||
119 | } |
||
120 | 4 | return ! empty($convert) ? $result : $result[0]; |
|
121 | } |
||
122 | |||
123 | /** |
||
124 | * |
||
125 | * {@inheritDoc} |
||
126 | * |
||
127 | */ |
||
128 | 6 | public function getATime($timeformat = false, $pathname = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
129 | { |
||
130 | 6 | $atime = empty($pathname) ? parent::getATime() : fileatime($this->makeAbsolute($pathname)); |
|
131 | 6 | if (! empty($timeformat) && is_int($atime)) { |
|
132 | switch ($timeformat) { |
||
133 | 4 | case 'ago': |
|
134 | 4 | $atime = $this->ct_ago($atime, 'y,m,d,h,i,s', false, true); |
|
135 | 4 | break; |
|
136 | 4 | case 'ago.single': |
|
137 | 4 | $atime = $this->ct_ago($atime, 'y,m,d,h,i,s', false, true, true); |
|
138 | 4 | break; |
|
139 | default: |
||
140 | 4 | $atime = date($timeformat, $atime); |
|
141 | 4 | break; |
|
142 | } |
||
143 | } |
||
144 | 6 | return $atime; |
|
145 | } |
||
146 | |||
147 | /** |
||
148 | * |
||
149 | * {@inheritDoc} |
||
150 | * |
||
151 | */ |
||
152 | 6 | public function getCTime($timeformat = false, $pathname = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
153 | { |
||
154 | 6 | $ctime = empty($pathname) ? parent::getCTime() : filectime($this->makeAbsolute($pathname)); |
|
155 | 6 | if (! empty($timeformat) && is_int($ctime)) { |
|
156 | switch ($timeformat) { |
||
157 | 4 | case 'ago': |
|
158 | 4 | $ctime = $this->ct_ago($ctime, 'y,m,d,h,i,s', false, true); |
|
159 | 4 | break; |
|
160 | 4 | case 'ago.single': |
|
161 | 4 | $ctime = $this->ct_ago($ctime, 'y,m,d,h,i,s', false, true, true); |
|
162 | 4 | break; |
|
163 | default: |
||
164 | 4 | $ctime = date($timeformat, $ctime); |
|
165 | 4 | break; |
|
166 | } |
||
167 | } |
||
168 | 6 | return $ctime; |
|
169 | } |
||
170 | |||
171 | /** |
||
172 | * |
||
173 | * {@inheritDoc} |
||
174 | * |
||
175 | */ |
||
176 | 6 | public function getMTime($timeformat = false, $pathname = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
177 | { |
||
178 | 6 | $mtime = empty($pathname) ? parent::getMTime() : filemtime($this->makeAbsolute($pathname)); |
|
179 | 6 | if (! empty($timeformat) && is_int($mtime)) { |
|
180 | switch ($timeformat) { |
||
181 | 4 | case 'ago': |
|
182 | 4 | $mtime = $this->ct_ago($mtime, 'y,m,d,h,i,s', false, true); |
|
183 | 4 | break; |
|
184 | 4 | case 'ago.single': |
|
185 | 4 | $mtime = $this->ct_ago($mtime, 'y,m,d,h,i,s', false, true, true); |
|
186 | 4 | break; |
|
187 | default: |
||
188 | 4 | $mtime = date($timeformat, $mtime); |
|
189 | 4 | break; |
|
190 | } |
||
191 | } |
||
192 | 6 | return $mtime; |
|
193 | } |
||
194 | |||
195 | /** |
||
196 | * |
||
197 | * {@inheritDoc} |
||
198 | * |
||
199 | */ |
||
200 | 18 | public function ct_ago($timestamp, $date_format = 'y,m,d,h,i,s', $sfx = true, $ommit_zero = true, $ago_single = true, $clocale = []) |
|
201 | { |
||
202 | 18 | $locale = array_merge( |
|
203 | array( |
||
204 | 'y' => array( |
||
205 | 'y', |
||
206 | 'year', |
||
207 | 'years' |
||
208 | 18 | ), |
|
209 | 'm' => array( |
||
210 | 'm', |
||
211 | 'month', |
||
212 | 'months' |
||
213 | ), |
||
214 | 'd' => $d = array( |
||
215 | 18 | 'd', |
|
216 | 'day', |
||
217 | 'days' |
||
218 | ), |
||
219 | 'h' => array( |
||
220 | 'h', |
||
221 | 'hour', |
||
222 | 'hours' |
||
223 | ), |
||
224 | 'i' => array( |
||
225 | 'm', |
||
226 | 'minute', |
||
227 | 'minutes' |
||
228 | ), |
||
229 | 's' => array( |
||
230 | 's', |
||
231 | 'second', |
||
232 | 'seconds' |
||
233 | ), |
||
234 | 18 | 'days' => $d, |
|
235 | 18 | 'ago' => 'ago', |
|
236 | 18 | 'now' => 'just now' |
|
237 | ), $clocale); |
||
238 | |||
239 | 18 | $date = new DateTime(); |
|
240 | 18 | $date->setTimestamp($timestamp); |
|
241 | |||
242 | 18 | $interval = $date->diff(new DateTime('now')); |
|
243 | |||
244 | 18 | for ($df = strtok($date_format, ','); $df !== false; $df = strtok(",")) { |
|
245 | 18 | $lkey = ($df !== 'a') ? strtolower($df) : 'days'; |
|
246 | |||
247 | 18 | if ($ommit_zero && $interval->$lkey === 0) |
|
248 | 16 | continue; |
|
249 | |||
250 | 10 | $fparam = $df . (empty($sfx) ? $locale[$lkey][0] : ' ' . |
|
251 | 10 | (($interval->$lkey === 1) ? $locale[$lkey][1] : $locale[$lkey][2])); |
|
252 | |||
253 | 10 | if (! empty($ago_single) && ! empty($dfs)) |
|
254 | 2 | break; |
|
255 | else |
||
256 | 10 | $dfs = ! empty($dfs) ? $dfs . "%$fparam " : "%$fparam "; |
|
257 | } |
||
258 | 18 | if (empty($dfs)) |
|
259 | 8 | $ret = $locale['now']; |
|
260 | else |
||
261 | 10 | $ret = $interval->format($dfs) . $locale['ago']; |
|
262 | 18 | return $ret; |
|
263 | } |
||
264 | |||
265 | /** |
||
266 | * |
||
267 | * {@inheritDoc} |
||
268 | * |
||
269 | */ |
||
270 | 4 | public function openFile($open_mode = "r", $use_include_path = false, $context = null) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
271 | { |
||
272 | 4 | if (! method_exists(get_parent_class($this), 'openFile')) |
|
273 | 1 | return false; |
|
274 | |||
275 | 3 | return ! $this->isDir() ? (! empty($context) ? parent::openFile($open_mode, $use_include_path, |
|
276 | 3 | $context) : parent::openFile($open_mode, $use_include_path)) : false; |
|
277 | } |
||
278 | |||
279 | /** |
||
280 | * |
||
281 | * {@inheritDoc} |
||
282 | * |
||
283 | */ |
||
284 | 144 | public function setFileClass($class_name = "\HOWI3\libhowi\Filesystem\php7\Objects\FileObject") |
|
285 | { |
||
286 | 144 | if (! method_exists(get_parent_class($this), 'setFileClass')) |
|
287 | 1 | return false; |
|
288 | |||
289 | 143 | if (is_subclass_of($class_name, 'SplFileObject') || $class_name === 'SplFileObject') { |
|
290 | 143 | parent::setFileClass($class_name); |
|
291 | 143 | return true; |
|
292 | } |
||
293 | 3 | return false; |
|
294 | } |
||
295 | |||
296 | /** |
||
297 | * |
||
298 | * {@inheritDoc} |
||
299 | * |
||
300 | */ |
||
301 | 144 | public function setInfoClass($class_name = "\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject") |
|
302 | { |
||
303 | 144 | if (! method_exists(get_parent_class($this), 'setInfoClass')) |
|
304 | 1 | return false; |
|
305 | |||
306 | 143 | if (is_subclass_of($class_name, 'SplFileInfo') || $class_name === 'SplFileInfo') { |
|
307 | 143 | parent::setInfoClass($class_name); |
|
308 | 143 | return true; |
|
309 | } |
||
310 | 3 | return false; |
|
311 | } |
||
312 | |||
313 | /** |
||
314 | * |
||
315 | * {@inheritDoc} |
||
316 | * |
||
317 | */ |
||
318 | 4 | public function getOwnerName($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
319 | { |
||
320 | 4 | $userID = empty($filename) && method_exists(get_parent_class($this), 'getOwner') ? parent::getOwner() : (! empty( |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getOwner() instead of getOwnerName() ). Are you sure this is correct? If so, you might want to change this to $this->getOwner() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
321 | 4 | $filename) ? fileowner($this->makeAbsolute($filename)) : false); |
|
322 | 4 | $user = ! empty($userID) ? posix_getpwuid($userID) : false; |
|
323 | 4 | return is_array($user) && array_key_exists('name', $user) ? $user['name'] : false; |
|
324 | } |
||
325 | |||
326 | /** |
||
327 | * |
||
328 | * {@inheritDoc} |
||
329 | * |
||
330 | */ |
||
331 | 4 | public function getGroupName($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
332 | { |
||
333 | 4 | $groupID = empty($filename) ? ((method_exists(get_parent_class($this), 'getGroup')) ? parent::getGroup() : false) : filegroup( |
|
0 ignored issues
–
show
It seems like you call parent on a different method (
getGroup() instead of getGroupName() ). Are you sure this is correct? If so, you might want to change this to $this->getGroup() .
This check looks for a call to a parent method whose name is different than the method from which it is called. Consider the following code: class Daddy
{
protected function getFirstName()
{
return "Eidur";
}
protected function getSurName()
{
return "Gudjohnsen";
}
}
class Son
{
public function getFirstName()
{
return parent::getSurname();
}
}
The ![]() |
|||
334 | 4 | $this->makeAbsolute($filename)); |
|
335 | 4 | $group = ! empty($groupID) ? posix_getgrgid($groupID) : false; |
|
336 | 4 | return ! empty($group) && array_key_exists('name', $group) ? $group['name'] : false; |
|
337 | } |
||
338 | |||
339 | /** |
||
340 | * |
||
341 | * {@inheritDoc} |
||
342 | * |
||
343 | */ |
||
344 | 5 | public function getRealpath($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
345 | { |
||
346 | 5 | return ! empty($filename) ? realpath($this->makeAbsolute($filename)) : ((method_exists( |
|
347 | 5 | get_parent_class($this), 'getRealpath')) ? parent::getRealpath() : false); |
|
348 | } |
||
349 | |||
350 | /** |
||
351 | * |
||
352 | * {@inheritDoc} |
||
353 | * |
||
354 | */ |
||
355 | 4 | public function getPathInfo($filename = false, $flags = false, |
|
356 | $class_name = '\HOWI3\libhowi\Filesystem\php7\Objects\InfoObject') |
||
357 | { |
||
358 | 4 | return ! empty($filename) ? empty($flags) ? pathinfo($this->makeAbsolute($filename)) : pathinfo( |
|
359 | 4 | $this->makeAbsolute($filename), $flags) : (method_exists(get_parent_class($this), 'getPathInfo') ? parent::getPathInfo( |
|
360 | 4 | $class_name) : false); |
|
361 | } |
||
362 | |||
363 | /** |
||
364 | * |
||
365 | * {@inheritDoc} |
||
366 | * |
||
367 | */ |
||
368 | 26 | public function getPath() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
369 | { |
||
370 | 26 | return method_exists(get_parent_class($this), 'getPath') ? parent::getPath() : (property_exists($this, |
|
371 | 26 | 'path') ? $this->path : dirname($this->getPathname())); |
|
0 ignored issues
–
show
The property
path does not exist. Did you maybe forget to declare it?
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code: class MyClass { }
$x = new MyClass();
$x->foo = true;
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: class MyClass {
public $foo;
}
$x = new MyClass();
$x->foo = true;
![]() |
|||
372 | } |
||
373 | |||
374 | /** |
||
375 | * |
||
376 | * {@inheritDoc} |
||
377 | * |
||
378 | */ |
||
379 | 8 | public function getPathname() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
380 | { |
||
381 | 8 | return method_exists(get_parent_class($this), 'getPathname') ? parent::getPathname() : $this->getCwd(); |
|
382 | } |
||
383 | |||
384 | /** |
||
385 | * |
||
386 | * {@inheritDoc} |
||
387 | * |
||
388 | */ |
||
389 | 4 | public function getGroup($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
390 | { |
||
391 | 4 | return empty($filename) ? ((method_exists(get_parent_class($this), 'getGroup')) ? parent::getGroup() : false) : filegroup( |
|
392 | 4 | $this->makeAbsolute($filename)); |
|
393 | } |
||
394 | |||
395 | /** |
||
396 | * |
||
397 | * {@inheritDoc} |
||
398 | * |
||
399 | */ |
||
400 | 4 | public function getOwner($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
401 | { |
||
402 | 4 | return empty($filename) ? ((method_exists(get_parent_class($this), 'getOwner')) ? parent::getOwner() : false) : fileowner( |
|
403 | 4 | $this->makeAbsolute($filename)); |
|
404 | } |
||
405 | |||
406 | /** |
||
407 | * |
||
408 | * {@inheritDoc} |
||
409 | * |
||
410 | */ |
||
411 | 4 | public function getInode($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
412 | { |
||
413 | 4 | return empty($filename) ? ((method_exists(get_parent_class($this), 'getInode')) ? parent::getInode() : false) : fileinode( |
|
414 | 4 | $this->makeAbsolute($filename)); |
|
415 | } |
||
416 | |||
417 | /** |
||
418 | * |
||
419 | * {@inheritDoc} |
||
420 | * |
||
421 | */ |
||
422 | 6 | public function getBasename($suffix = false, $pathname = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
423 | { |
||
424 | 6 | $pathname = ! empty($pathname) ? $pathname : ($this->isDot() ? $this->getPath() : false); |
|
425 | 6 | $suffix = ! empty($suffix) ? $suffix : ''; |
|
426 | 6 | return ! empty($pathname) || ! method_exists(get_parent_class($this), 'getBasename') ? basename( |
|
427 | 6 | $pathname, $suffix) : parent::getBasename($suffix); |
|
428 | } |
||
429 | |||
430 | /** |
||
431 | * |
||
432 | * {@inheritDoc} |
||
433 | * |
||
434 | */ |
||
435 | 5 | public function getPerms($filename = false) |
|
436 | { |
||
437 | 5 | $perms = empty($filename) ? ((method_exists(get_parent_class($this), 'getPerms')) ? parent::getPerms() : false) : fileperms( |
|
438 | 5 | $this->makeAbsolute($filename)); |
|
439 | 5 | return ! empty($perms) ? (int) ltrim(substr(sprintf('%o', $perms), - 4), '0') : false; |
|
440 | } |
||
441 | |||
442 | /** |
||
443 | * |
||
444 | * {@inheritDoc} |
||
445 | * |
||
446 | */ |
||
447 | 6 | public function getType($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
448 | { |
||
449 | 6 | return ! empty($filename) ? filetype($this->makeAbsolute($filename)) : ((method_exists( |
|
450 | 6 | get_parent_class($this), 'getType')) ? parent::getType() : false); |
|
451 | } |
||
452 | |||
453 | /** |
||
454 | * |
||
455 | * {@inheritDoc} |
||
456 | * |
||
457 | */ |
||
458 | 10 | public function isDot() |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
459 | { |
||
460 | 10 | return ((method_exists(get_parent_class($this), 'isDot')) ? parent::isDot() : false); |
|
461 | } |
||
462 | |||
463 | /** |
||
464 | * |
||
465 | * {@inheritDoc} |
||
466 | * |
||
467 | */ |
||
468 | 241 | public function isAbsolute($path = false) |
|
469 | { |
||
470 | 241 | return ((strspn($path, DIRECTORY_SEPARATOR, 0, 1) + (ctype_alnum($path) ? 0 : 1) + |
|
471 | 241 | (strpos($path, ':') === false) + (strpos($path, "/../") === false ? 1 : 0) + |
|
472 | 241 | (filter_var($path, FILTER_VALIDATE_URL) === false ? 1 : 0) === 5) ? true : false); |
|
473 | } |
||
474 | |||
475 | /** |
||
476 | * |
||
477 | * {@inheritDoc} |
||
478 | * |
||
479 | */ |
||
480 | 241 | public function isRelative($path = false) |
|
481 | { |
||
482 | // ^(?=.*?(.))((?!(^\/)).)*$ |
||
483 | 241 | return (preg_match('/^[^\/].*$/', $path) === 1) ? true : false; |
|
484 | } |
||
485 | |||
486 | /** |
||
487 | * |
||
488 | * {@inheritDoc} |
||
489 | * |
||
490 | */ |
||
491 | 241 | public function isWritable($path = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
492 | { |
||
493 | 241 | return empty($path) ? ((method_exists(get_parent_class($this), 'isWritable')) ? parent::isWritable() : false) : is_writable( |
|
494 | 241 | $this->makeAbsolute($path)); |
|
495 | } |
||
496 | |||
497 | /** |
||
498 | * |
||
499 | * {@inheritDoc} |
||
500 | * |
||
501 | */ |
||
502 | 5 | public function isReadable($path = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
503 | { |
||
504 | 5 | return empty($path) ? ((method_exists(get_parent_class($this), 'isReadable')) ? parent::isReadable() : false) : is_readable( |
|
505 | 5 | $this->makeAbsolute($path)); |
|
506 | } |
||
507 | |||
508 | /** |
||
509 | * |
||
510 | * {@inheritDoc} |
||
511 | * |
||
512 | */ |
||
513 | 65 | public function isDir($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
514 | { |
||
515 | 65 | return empty($filename) ? ((method_exists(get_parent_class($this), 'isDir')) ? parent::isDir() : false) : is_dir( |
|
516 | 65 | $this->makeAbsolute($filename)); |
|
517 | } |
||
518 | |||
519 | /** |
||
520 | * |
||
521 | * {@inheritDoc} |
||
522 | * |
||
523 | */ |
||
524 | 4 | public function isExecutable($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
525 | { |
||
526 | 4 | return ! empty($filename) ? is_executable($this->makeAbsolute($filename)) : ((method_exists( |
|
527 | 4 | get_parent_class($this), 'isExecutable')) ? parent::isExecutable() : false); |
|
528 | } |
||
529 | |||
530 | /** |
||
531 | * |
||
532 | * {@inheritDoc} |
||
533 | * |
||
534 | */ |
||
535 | 6 | public function isFile($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
536 | { |
||
537 | 6 | return ! empty($filename) ? is_file($this->makeAbsolute($filename)) : ((method_exists( |
|
538 | 6 | get_parent_class($this), 'isFile')) ? parent::isFile() : false); |
|
539 | } |
||
540 | |||
541 | /** |
||
542 | * |
||
543 | * {@inheritDoc} |
||
544 | * |
||
545 | */ |
||
546 | 7 | public function isLink($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
547 | { |
||
548 | 7 | return ! empty($filename) ? is_link($this->makeAbsolute($filename)) : ((method_exists( |
|
549 | 7 | get_parent_class($this), 'isLink')) ? parent::isLink() : false); |
|
550 | } |
||
551 | |||
552 | /** |
||
553 | * |
||
554 | * {@inheritDoc} |
||
555 | * |
||
556 | */ |
||
557 | 241 | public function makeAbsolute($path = false) |
|
558 | { |
||
559 | 241 | if (! empty($path) && $this->isAbsolute($path)) |
|
560 | 241 | $absolute_path = $path; |
|
561 | 241 | elseif (! empty($path) && $this->isRelative($path)) { |
|
562 | |||
563 | 241 | if (preg_match('/^(~\/)/', $path) === 1) { |
|
564 | 241 | $absolute_path = getenv("HOME") . substr($path, 1); |
|
565 | 8 | } elseif (preg_match('/^(.\/|..\/)/', $path) === 1) { |
|
566 | 6 | $absolute_path = realpath($path); |
|
567 | } else |
||
568 | 241 | $absolute_path = $this->getCwd() . ($path !== '.' ? DIRECTORY_SEPARATOR . $path : ''); |
|
569 | } else { |
||
570 | 5 | $absolute_path = $path; |
|
571 | } |
||
572 | 241 | return $absolute_path; |
|
573 | } |
||
574 | |||
575 | /** |
||
576 | * |
||
577 | * {@inheritDoc} |
||
578 | * |
||
579 | */ |
||
580 | 101 | public function exists($pathname = false) |
|
581 | { |
||
582 | 101 | if (empty($pathname)) |
|
583 | 1 | return false; |
|
584 | |||
585 | 101 | $pathname = $this->makeAbsolute($pathname); |
|
586 | |||
587 | 101 | return ! empty($pathname) ? file_exists($pathname) : false; |
|
588 | } |
||
589 | |||
590 | /** |
||
591 | * |
||
592 | * {@inheritDoc} |
||
593 | * |
||
594 | */ |
||
595 | 9 | public function getFilename($filename = false) |
|
0 ignored issues
–
show
The return type could not be reliably inferred; please add a
@return annotation.
Our type inference engine in quite powerful, but sometimes the code does not
provide enough clues to go by. In these cases we request you to add a ![]() |
|||
596 | { |
||
597 | 9 | return ! empty($filename) ? basename($this->makeAbsolute($filename)) : ((method_exists( |
|
598 | 9 | get_parent_class($this), 'getFilename')) ? parent::getFilename() : false); |
|
599 | } |
||
600 | |||
601 | /** |
||
602 | * |
||
603 | * {@inheritDoc} |
||
604 | * |
||
605 | */ |
||
606 | 4 | public function getExtension($filename = false) |
|
607 | { |
||
608 | 4 | return ! empty($filename) ? pathinfo($this->makeAbsolute($filename), PATHINFO_EXTENSION) : ((method_exists( |
|
609 | 4 | get_parent_class($this), 'getExtension')) ? parent::getExtension() : false); |
|
610 | } |
||
611 | } |
||
612 |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.