1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace kint\parsers\custom; |
4
|
|
|
|
5
|
|
|
use kint\inc\KintParser; |
6
|
|
|
|
7
|
|
|
/** |
8
|
|
|
* Class Kint_Parsers_FsPath |
9
|
|
|
*/ |
10
|
|
|
class Kint_Parsers_FsPath extends KintParser |
11
|
|
|
{ |
12
|
|
|
/** |
13
|
|
|
* @param mixed $variable |
14
|
|
|
* |
15
|
|
|
* @return false|null |
16
|
|
|
*/ |
17
|
1 |
|
protected function _parse(&$variable) |
18
|
|
|
{ |
19
|
|
|
/** @noinspection PhpUsageOfSilenceOperatorInspection */ |
20
|
|
|
if ( |
21
|
1 |
|
is_object($variable) |
22
|
1 |
|
|| is_array($variable) |
23
|
1 |
|
|| (string)$variable !== $variable |
24
|
1 |
|
|| strlen($variable) > 2048 |
25
|
1 |
|
|| preg_match('[[:?<>"*|]]', $variable) |
26
|
1 |
|
|| !@is_readable($variable) # f@#! PHP and its random warnings |
27
|
|
|
) { |
28
|
1 |
|
return false; |
29
|
|
|
} |
30
|
|
|
|
31
|
|
|
try { |
32
|
|
|
$fileInfo = new \SplFileInfo($variable); |
33
|
|
|
$flags = array(); |
34
|
|
|
$perms = $fileInfo->getPerms(); |
35
|
|
|
|
36
|
|
View Code Duplication |
if (($perms & 0xC000) === 0xC000) { |
|
|
|
|
37
|
|
|
$type = 'File socket'; |
38
|
|
|
$flags[] = 's'; |
39
|
|
|
} elseif (($perms & 0xA000) === 0xA000) { |
40
|
|
|
$type = 'File symlink'; |
41
|
|
|
$flags[] = 'l'; |
42
|
|
|
} elseif (($perms & 0x8000) === 0x8000) { |
43
|
|
|
$type = 'File'; |
44
|
|
|
$flags[] = '-'; |
45
|
|
|
} elseif (($perms & 0x6000) === 0x6000) { |
46
|
|
|
$type = 'Block special file'; |
47
|
|
|
$flags[] = 'b'; |
48
|
|
|
} elseif (($perms & 0x4000) === 0x4000) { |
49
|
|
|
$type = 'Directory'; |
50
|
|
|
$flags[] = 'd'; |
51
|
|
|
} elseif (($perms & 0x2000) === 0x2000) { |
52
|
|
|
$type = 'Character special file'; |
53
|
|
|
$flags[] = 'c'; |
54
|
|
|
} elseif (($perms & 0x1000) === 0x1000) { |
55
|
|
|
$type = 'FIFO pipe file'; |
56
|
|
|
$flags[] = 'p'; |
57
|
|
|
} else { |
58
|
|
|
$type = 'Unknown file'; |
59
|
|
|
$flags[] = 'u'; |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
// owner |
63
|
|
|
$flags[] = (($perms & 0x0100) ? 'r' : '-'); |
64
|
|
|
$flags[] = (($perms & 0x0080) ? 'w' : '-'); |
65
|
|
|
$flags[] = (($perms & 0x0040) ? (($perms & 0x0800) ? 's' : 'x') : (($perms & 0x0800) ? 'S' : '-')); |
66
|
|
|
|
67
|
|
|
// group |
68
|
|
|
$flags[] = (($perms & 0x0020) ? 'r' : '-'); |
69
|
|
|
$flags[] = (($perms & 0x0010) ? 'w' : '-'); |
70
|
|
|
$flags[] = (($perms & 0x0008) ? (($perms & 0x0400) ? 's' : 'x') : (($perms & 0x0400) ? 'S' : '-')); |
71
|
|
|
|
72
|
|
|
// world |
73
|
|
|
$flags[] = (($perms & 0x0004) ? 'r' : '-'); |
74
|
|
|
$flags[] = (($perms & 0x0002) ? 'w' : '-'); |
75
|
|
|
$flags[] = (($perms & 0x0001) ? (($perms & 0x0200) ? 't' : 'x') : (($perms & 0x0200) ? 'T' : '-')); |
76
|
|
|
|
77
|
|
|
$this->type = $type; |
78
|
|
|
$this->size = sprintf('%.2fK', $fileInfo->getSize() / 1024); |
|
|
|
|
79
|
|
|
$this->value = implode($flags); |
80
|
|
|
|
81
|
|
|
} catch (\Exception $e) { |
82
|
|
|
return false; |
83
|
|
|
} |
84
|
|
|
} |
85
|
|
|
} |
86
|
|
|
|
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.