Issues (446)

Security Analysis    no request data  

This project does not seem to handle request data directly as such no vulnerable execution paths were found.

  Cross-Site Scripting
Cross-Site Scripting enables an attacker to inject code into the response of a web-request that is viewed by other users. It can for example be used to bypass access controls, or even to take over other users' accounts.
  File Exposure
File Exposure allows an attacker to gain access to local files that he should not be able to access. These files can for example include database credentials, or other configuration files.
  File Manipulation
File Manipulation enables an attacker to write custom data to files. This potentially leads to injection of arbitrary code on the server.
  Object Injection
Object Injection enables an attacker to inject an object into PHP code, and can lead to arbitrary code execution, file exposure, or file manipulation attacks.
  Code Injection
Code Injection enables an attacker to execute arbitrary code on the server.
  Response Splitting
Response Splitting can be used to send arbitrary responses.
  File Inclusion
File Inclusion enables an attacker to inject custom files into PHP's file loading mechanism, either explicitly passed to include, or for example via PHP's auto-loading mechanism.
  Command Injection
Command Injection enables an attacker to inject a shell command that is execute with the privileges of the web-server. This can be used to expose sensitive data, or gain access of your server.
  SQL Injection
SQL Injection enables an attacker to execute arbitrary SQL code on your database server gaining access to user data, or manipulating user data.
  XPath Injection
XPath Injection enables an attacker to modify the parts of XML document that are read. If that XML document is for example used for authentication, this can lead to further vulnerabilities similar to SQL Injection.
  LDAP Injection
LDAP Injection enables an attacker to inject LDAP statements potentially granting permission to run unauthorized queries, or modify content inside the LDAP tree.
  Header Injection
  Other Vulnerability
This category comprises other attack vectors such as manipulating the PHP runtime, loading custom extensions, freezing the runtime, or similar.
  Regex Injection
Regex Injection enables an attacker to execute arbitrary code in your PHP process.
  XML Injection
XML Injection enables an attacker to read files on your local filesystem including configuration files, or can be abused to freeze your web-server process.
  Variable Injection
Variable Injection enables an attacker to overwrite program variables with custom data, and can lead to further vulnerabilities.
Unfortunately, the security analysis is currently not available for your project. If you are a non-commercial open-source project, please contact support to gain access.

php5/TraitForSharedMethods.inc (32 issues)

Upgrade to new PHP Analysis Engine

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\php5;
25
26
use \RecursiveDirectoryIterator;
27
use \RecursiveIteratorIterator;
28
use \DateTime;
29
30 View Code Duplication
trait TraitForSharedMethods
0 ignored issues
show
This class seems to be duplicated in your project.

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.

Loading history...
31
{
32
33
    /**
34
     *
35
     * {@inheritDoc}
36
     *
37
     */
38 490
    protected function setCwd($path = false, $validate_dir_name = false)
39
    {
40 490
        if (empty($path))
41 490
            $current_working_directory = $this->getCwd();
42
        else
43 16
            $current_working_directory = $this->makeAbsolute($path);
44
        
45 490
        if (! empty($validate_dir_name) && (basename($current_working_directory) !== $validate_dir_name))
46 490
            return false;
47
        
48 490
        if (! is_dir($current_working_directory) || ! is_readable($current_working_directory) ||
49 490
             ! chdir($current_working_directory)) {
50 8
            $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 Idable provides a method equalsId that in turn relies on the method getId(). If this method does not exist on a class mixing in this trait, the method will fail.

Adding the getId() as an abstract method to the trait will make sure it is available.

Loading history...
51 8
            return false;
52
        }
53 490
        $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;
Loading history...
54 490
        return true;
55
    }
56
57
    /**
58
     *
59
     * {@inheritDoc}
60
     *
61
     */
62 490
    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 @return annotation as described here.

Loading history...
63
    {
64 490
        if (empty($this->cwd))
65 490
            $this->cwd = getcwd();
66
        
67 490
        return $this->cwd;
68
    }
69
70
    /**
71
     *
72
     * {@inheritDoc}
73
     *
74
     */
75 14
    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 @return annotation as described here.

Loading history...
76
    {
77 14
        $filename = ! empty($filename) ? $this->makeAbsolute($filename) : false;
78 14
        $bytestotal = empty($filename) ? ((method_exists(get_parent_class($this), 'getSize')) ? parent::getSize() : false) : filesize(
79 14
            $filename);
80
        
81 14
        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.

Loading history...
82 14
            return $bytestotal;
83
        
84
        $suffixes = array(
85 10
            'B',
86 10
            'kB',
87 10
            'MB',
88 10
            'GB',
89 10
            'TB',
90 10
            'PB',
91 10
            'EB',
92 10
            'ZB',
93
            'YB'
94 10
        );
95 10
        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.

Loading history...
96 6
            $path = ((method_exists(get_class($this), 'getPathname')) ? $this->getPathname() : $filename);
97 6
            if ($path === '/home/nitrotrigger/tmp/libhowi-filesystem/log/phpunit_test.log')
98 6
                die('ss');
99
            
100 6
            foreach (new RecursiveIteratorIterator(
101 6
                new RecursiveDirectoryIterator($path, RecursiveDirectoryIterator::SKIP_DOTS)) as $object) {
102 6
                $bytestotal += $object->getSize();
103 6
            }
104 6
            if (! $convert)
105 6
                return $bytestotal;
106 4
        }
107 8
        $base = log($bytestotal, 1024);
108
        
109
        $result = [
110 8
            0,
111
            'B'
112 8
        ];
113 8
        if ($bytestotal > 0) {
114
            
115
            $result = array(
116 8
                round(pow(1024, $base - floor($base)), 2),
117 8
                $suffixes[floor($base)]
118 8
            );
119 8
        }
120 8
        return ! empty($convert) ? $result : $result[0];
121
    }
122
123
    /**
124
     *
125
     * {@inheritDoc}
126
     *
127
     */
128 12
    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 @return annotation as described here.

Loading history...
129
    {
130 12
        $atime = empty($pathname) ? parent::getATime() : fileatime($this->makeAbsolute($pathname));
131 12
        if (! empty($timeformat) && is_int($atime)) {
132
            switch ($timeformat) {
133 8
                case 'ago':
134 8
                    $atime = $this->ct_ago($atime, 'y,m,d,h,i,s', false, true);
135 8
                    break;
136 8
                case 'ago.single':
137 8
                    $atime = $this->ct_ago($atime, 'y,m,d,h,i,s', false, true, true);
138 8
                    break;
139 8
                default:
140 8
                    $atime = date($timeformat, $atime);
141 8
                    break;
142 8
            }
143 8
        }
144 12
        return $atime;
145
    }
146
147
    /**
148
     *
149
     * {@inheritDoc}
150
     *
151
     */
152 12
    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 @return annotation as described here.

Loading history...
153
    {
154 12
        $ctime = empty($pathname) ? parent::getCTime() : filectime($this->makeAbsolute($pathname));
155 12
        if (! empty($timeformat) && is_int($ctime)) {
156
            switch ($timeformat) {
157 8
                case 'ago':
158 8
                    $ctime = $this->ct_ago($ctime, 'y,m,d,h,i,s', false, true);
159 8
                    break;
160 8
                case 'ago.single':
161 8
                    $ctime = $this->ct_ago($ctime, 'y,m,d,h,i,s', false, true, true);
162 8
                    break;
163 8
                default:
164 8
                    $ctime = date($timeformat, $ctime);
165 8
                    break;
166 8
            }
167 8
        }
168 12
        return $ctime;
169
    }
170
171
    /**
172
     *
173
     * {@inheritDoc}
174
     *
175
     */
176 12
    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 @return annotation as described here.

Loading history...
177
    {
178 12
        $mtime = empty($pathname) ? parent::getMTime() : filemtime($this->makeAbsolute($pathname));
179 12
        if (! empty($timeformat) && is_int($mtime)) {
180
            switch ($timeformat) {
181 8
                case 'ago':
182 8
                    $mtime = $this->ct_ago($mtime, 'y,m,d,h,i,s', false, true);
183 8
                    break;
184 8
                case 'ago.single':
185 8
                    $mtime = $this->ct_ago($mtime, 'y,m,d,h,i,s', false, true, true);
186 8
                    break;
187 8
                default:
188 8
                    $mtime = date($timeformat, $mtime);
189 8
                    break;
190 8
            }
191 8
        }
192 12
        return $mtime;
193
    }
194
195
    /**
196
     *
197
     * {@inheritDoc}
198
     *
199
     */
200 36
    public function ct_ago($timestamp, $date_format = 'y,m,d,h,i,s', $sfx = true, $ommit_zero = true, $ago_single = true, $clocale = [])
201
    {
202 36
        $locale = array_merge(
203
            array(
204
                'y' => array(
205 36
                    'y',
206 36
                    'year',
207
                    'years'
208 36
                ),
209
                'm' => array(
210 36
                    'm',
211 36
                    'month',
212
                    'months'
213 36
                ),
214
                'd' => $d = array(
215 36
                    'd',
216 36
                    'day',
217
                    'days'
218 36
                ),
219
                'h' => array(
220 36
                    'h',
221 36
                    'hour',
222
                    'hours'
223 36
                ),
224
                'i' => array(
225 36
                    'm',
226 36
                    'minute',
227
                    'minutes'
228 36
                ),
229
                's' => array(
230 36
                    's',
231 36
                    'second',
232
                    'seconds'
233 36
                ),
234 36
                'days' => $d,
235 36
                'ago' => 'ago',
236
                'now' => 'just now'
237 36
            ), $clocale);
238
        
239 36
        $date = new DateTime();
240 36
        $date->setTimestamp($timestamp);
241
        
242 36
        $interval = $date->diff(new DateTime('now'));
243
        
244 36
        for ($df = strtok($date_format, ','); $df !== false; $df = strtok(",")) {
245 36
            $lkey = ($df !== 'a') ? strtolower($df) : 'days';
246
            
247 36
            if ($ommit_zero && $interval->$lkey === 0)
248 36
                continue;
249
            
250 22
            $fparam = $df . (empty($sfx) ? $locale[$lkey][0] : ' ' .
251 22
                 (($interval->$lkey === 1) ? $locale[$lkey][1] : $locale[$lkey][2]));
252
            
253 22
            if (! empty($ago_single) && ! empty($dfs))
254 22
                break;
255
            else
256 22
                $dfs = ! empty($dfs) ? $dfs . "%$fparam " : "%$fparam ";
257 22
        }
258 36
        if (empty($dfs))
259 36
            $ret = $locale['now'];
260
        else
261 22
            $ret = $interval->format($dfs) . $locale['ago'];
262 36
        return $ret;
263
    }
264
265
    /**
266
     *
267
     * {@inheritDoc}
268
     *
269
     */
270 8
    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 @return annotation as described here.

Loading history...
271
    {
272 8
        if (! method_exists(get_parent_class($this), 'openFile'))
273 8
            return false;
274
        
275 6
        return ! $this->isDir() ? (! empty($context) ? parent::openFile($open_mode, $use_include_path, 
276 6
            $context) : parent::openFile($open_mode, $use_include_path)) : false;
277
    }
278
279
    /**
280
     *
281
     * {@inheritDoc}
282
     *
283
     */
284 290
    public function setFileClass($class_name = "\HOWI3\libhowi\Filesystem\php5\Objects\FileObject")
285
    {
286 290
        if (! method_exists(get_parent_class($this), 'setFileClass'))
287 290
            return false;
288
        
289 288
        if (is_subclass_of($class_name, 'SplFileObject') || $class_name === 'SplFileObject') {
290 288
            parent::setFileClass($class_name);
291 288
            return true;
292
        }
293 6
        return false;
294
    }
295
296
    /**
297
     *
298
     * {@inheritDoc}
299
     *
300
     */
301 290
    public function setInfoClass($class_name = "\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject")
302
    {
303 290
        if (! method_exists(get_parent_class($this), 'setInfoClass'))
304 290
            return false;
305
        
306 288
        if (is_subclass_of($class_name, 'SplFileInfo') || $class_name === 'SplFileInfo') {
307 288
            parent::setInfoClass($class_name);
308 288
            return true;
309
        }
310 6
        return false;
311
    }
312
313
    /**
314
     *
315
     * {@inheritDoc}
316
     *
317
     */
318 8
    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 @return annotation as described here.

Loading history...
319
    {
320 8
        $userID = empty($filename) && method_exists(get_parent_class($this), 'getOwner') ? parent::getOwner() : (! empty(
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
321 8
            $filename) ? fileowner($this->makeAbsolute($filename)) : false);
322 8
        $user = ! empty($userID) ? posix_getpwuid($userID) : false;
323 8
        return is_array($user) && array_key_exists('name', $user) ? $user['name'] : false;
324
    }
325
326
    /**
327
     *
328
     * {@inheritDoc}
329
     *
330
     */
331 8
    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 @return annotation as described here.

Loading history...
332
    {
333 8
        $groupID = empty($filename) ? ((method_exists(get_parent_class($this), 'getGroup')) ? parent::getGroup() : false) : filegroup(
0 ignored issues
show
Comprehensibility Bug introduced by
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 getFirstName() method in the Son calls the wrong method in the parent class.

Loading history...
334 8
            $this->makeAbsolute($filename));
335 8
        $group = ! empty($groupID) ? posix_getgrgid($groupID) : false;
336 8
        return ! empty($group) && array_key_exists('name', $group) ? $group['name'] : false;
337
    }
338
339
    /**
340
     *
341
     * {@inheritDoc}
342
     *
343
     */
344 10
    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 @return annotation as described here.

Loading history...
345
    {
346 10
        return ! empty($filename) ? realpath($this->makeAbsolute($filename)) : ((method_exists(
347 10
            get_parent_class($this), 'getRealpath')) ? parent::getRealpath() : false);
348
    }
349
350
    /**
351
     *
352
     * {@inheritDoc}
353
     *
354
     */
355 8
    public function getPathInfo($filename = false, $flags = false, 
356
        $class_name = '\HOWI3\libhowi\Filesystem\php5\Objects\InfoObject')
357
    {
358 8
        return ! empty($filename) ? empty($flags) ? pathinfo($this->makeAbsolute($filename)) : pathinfo(
359 8
            $this->makeAbsolute($filename), $flags) : (method_exists(get_parent_class($this), 'getPathInfo') ? parent::getPathInfo(
360 8
            $class_name) : false);
361
    }
362
363
    /**
364
     *
365
     * {@inheritDoc}
366
     *
367
     */
368 52
    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 @return annotation as described here.

Loading history...
369
    {
370 52
        return method_exists(get_parent_class($this), 'getPath') ? parent::getPath() : (property_exists($this, 
371 52
            '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;
Loading history...
372
    }
373
374
    /**
375
     *
376
     * {@inheritDoc}
377
     *
378
     */
379 16
    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 @return annotation as described here.

Loading history...
380
    {
381 16
        return method_exists(get_parent_class($this), 'getPathname') ? parent::getPathname() : $this->getCwd();
382
    }
383
384
    /**
385
     *
386
     * {@inheritDoc}
387
     *
388
     */
389 8
    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 @return annotation as described here.

Loading history...
390
    {
391 8
        return empty($filename) ? ((method_exists(get_parent_class($this), 'getGroup')) ? parent::getGroup() : false) : filegroup(
392 8
            $this->makeAbsolute($filename));
393
    }
394
395
    /**
396
     *
397
     * {@inheritDoc}
398
     *
399
     */
400 8
    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 @return annotation as described here.

Loading history...
401
    {
402 8
        return empty($filename) ? ((method_exists(get_parent_class($this), 'getOwner')) ? parent::getOwner() : false) : fileowner(
403 8
            $this->makeAbsolute($filename));
404
    }
405
406
    /**
407
     *
408
     * {@inheritDoc}
409
     *
410
     */
411 8
    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 @return annotation as described here.

Loading history...
412
    {
413 8
        return empty($filename) ? ((method_exists(get_parent_class($this), 'getInode')) ? parent::getInode() : false) : fileinode(
414 8
            $this->makeAbsolute($filename));
415
    }
416
417
    /**
418
     *
419
     * {@inheritDoc}
420
     *
421
     */
422 12
    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 @return annotation as described here.

Loading history...
423
    {
424 12
        $pathname = ! empty($pathname) ? $pathname : ($this->isDot() ? $this->getPath() : false);
425 12
        $suffix = ! empty($suffix) ? $suffix : '';
426 12
        return ! empty($pathname) || ! method_exists(get_parent_class($this), 'getBasename') ? basename(
427 12
            $pathname, $suffix) : parent::getBasename($suffix);
428
    }
429
430
    /**
431
     *
432
     * {@inheritDoc}
433
     *
434
     */
435 10
    public function getPerms($filename = false)
436
    {
437 10
        $perms = empty($filename) ? ((method_exists(get_parent_class($this), 'getPerms')) ? parent::getPerms() : false) : fileperms(
438 10
            $this->makeAbsolute($filename));
439 10
        return ! empty($perms) ? (int) ltrim(substr(sprintf('%o', $perms), - 4), '0') : false;
440
    }
441
442
    /**
443
     *
444
     * {@inheritDoc}
445
     *
446
     */
447 12
    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 @return annotation as described here.

Loading history...
448
    {
449 12
        return ! empty($filename) ? filetype($this->makeAbsolute($filename)) : ((method_exists(
450 12
            get_parent_class($this), 'getType')) ? parent::getType() : false);
451
    }
452
453
    /**
454
     *
455
     * {@inheritDoc}
456
     *
457
     */
458 20
    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 @return annotation as described here.

Loading history...
459
    {
460 20
        return ((method_exists(get_parent_class($this), 'isDot')) ? parent::isDot() : false);
461
    }
462
463
    /**
464
     *
465
     * {@inheritDoc}
466
     *
467
     */
468 490
    public function isAbsolute($path = false)
469
    {
470 490
        return ((strspn($path, DIRECTORY_SEPARATOR, 0, 1) + (ctype_alnum($path) ? 0 : 1) +
471 490
             (strpos($path, ':') === false) + (strpos($path, "/../") === false ? 1 : 0) +
472 490
             (filter_var($path, FILTER_VALIDATE_URL) === false ? 1 : 0) === 5) ? true : false);
473
    }
474
475
    /**
476
     *
477
     * {@inheritDoc}
478
     *
479
     */
480 490
    public function isRelative($path = false)
481
    {
482
        // ^(?=.*?(.))((?!(^\/)).)*$
483 490
        return (preg_match('/^[^\/].*$/', $path) === 1) ? true : false;
484
    }
485
486
    /**
487
     *
488
     * {@inheritDoc}
489
     *
490
     */
491 490
    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 @return annotation as described here.

Loading history...
492
    {
493 490
        return empty($path) ? ((method_exists(get_parent_class($this), 'isWritable')) ? parent::isWritable() : false) : is_writable(
494 490
            $this->makeAbsolute($path));
495
    }
496
497
    /**
498
     *
499
     * {@inheritDoc}
500
     *
501
     */
502 10
    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 @return annotation as described here.

Loading history...
503
    {
504 10
        return empty($path) ? ((method_exists(get_parent_class($this), 'isReadable')) ? parent::isReadable() : false) : is_readable(
505 10
            $this->makeAbsolute($path));
506
    }
507
508
    /**
509
     *
510
     * {@inheritDoc}
511
     *
512
     */
513 132
    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 @return annotation as described here.

Loading history...
514
    {
515 132
        return empty($filename) ? ((method_exists(get_parent_class($this), 'isDir')) ? parent::isDir() : false) : is_dir(
516 132
            $this->makeAbsolute($filename));
517
    }
518
519
    /**
520
     *
521
     * {@inheritDoc}
522
     *
523
     */
524 8
    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 @return annotation as described here.

Loading history...
525
    {
526 8
        return ! empty($filename) ? is_executable($this->makeAbsolute($filename)) : ((method_exists(
527 8
            get_parent_class($this), 'isExecutable')) ? parent::isExecutable() : false);
528
    }
529
530
    /**
531
     *
532
     * {@inheritDoc}
533
     *
534
     */
535 12
    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 @return annotation as described here.

Loading history...
536
    {
537 12
        return ! empty($filename) ? is_file($this->makeAbsolute($filename)) : ((method_exists(
538 12
            get_parent_class($this), 'isFile')) ? parent::isFile() : false);
539
    }
540
541
    /**
542
     *
543
     * {@inheritDoc}
544
     *
545
     */
546 14
    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 @return annotation as described here.

Loading history...
547
    {
548 14
        return ! empty($filename) ? is_link($this->makeAbsolute($filename)) : ((method_exists(
549 14
            get_parent_class($this), 'isLink')) ? parent::isLink() : false);
550
    }
551
552
    /**
553
     *
554
     * {@inheritDoc}
555
     *
556
     */
557 490
    public function makeAbsolute($path = false)
558
    {
559 490
        if (! empty($path) && $this->isAbsolute($path))
560 490
            $absolute_path = $path;
561 490
        elseif (! empty($path) && $this->isRelative($path)) {
562
            
563 490
            if (preg_match('/^(~\/)/', $path) === 1) {
564 490
                $absolute_path = getenv("HOME") . substr($path, 1);
565 490
            } elseif (preg_match('/^(.\/|..\/)/', $path) === 1) {
566 12
                $absolute_path = realpath($path);
567 12
            } else
568 6
                $absolute_path = $this->getCwd() . ($path !== '.' ? DIRECTORY_SEPARATOR . $path : '');
569 490
        } else {
570 10
            $absolute_path = $path;
571
        }
572 490
        return $absolute_path;
573
    }
574
575
    /**
576
     *
577
     * {@inheritDoc}
578
     *
579
     */
580 202
    public function exists($pathname = false)
581
    {
582 202
        if (empty($pathname))
583 202
            return false;
584
        
585 202
        $pathname = $this->makeAbsolute($pathname);
586
        
587 202
        return ! empty($pathname) ? file_exists($pathname) : false;
588
    }
589
590
    /**
591
     *
592
     * {@inheritDoc}
593
     *
594
     */
595 18
    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 @return annotation as described here.

Loading history...
596
    {
597 18
        return ! empty($filename) ? basename($this->makeAbsolute($filename)) : ((method_exists(
598 18
            get_parent_class($this), 'getFilename')) ? parent::getFilename() : false);
599
    }
600
601
    /**
602
     *
603
     * {@inheritDoc}
604
     *
605
     */
606 8
    public function getExtension($filename = false)
607
    {
608 8
        return ! empty($filename) ? pathinfo($this->makeAbsolute($filename), PATHINFO_EXTENSION) : ((method_exists(
609 8
            get_parent_class($this), 'getExtension')) ? parent::getExtension() : false);
610
    }
611
}
612