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