Completed
Pull Request — master (#133)
by Goffy
16:45
created

Kint_Objects_SplFileInfo::parse()   F

Complexity

Conditions 26
Paths > 20000

Size

Total Lines 65
Code Lines 48

Duplication

Lines 25
Ratio 38.46 %

Importance

Changes 1
Bugs 1 Features 0
Metric Value
c 1
b 1
f 0
dl 25
loc 65
rs 2.9158
cc 26
eloc 48
nc 262145
nop 1

How to fix   Long Method    Complexity   

Long Method

Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.

For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.

Commonly applied refactorings include:

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