Kint_Objects_SplFileInfo::parse()   F
last analyzed

Complexity

Conditions 25
Paths > 20000

Size

Total Lines 73
Code Lines 52

Duplication

Lines 25
Ratio 34.25 %

Code Coverage

Tests 4
CRAP Score 503.631

Importance

Changes 0
Metric Value
cc 25
dl 25
loc 73
ccs 4
cts 47
cp 0.0851
crap 503.631
rs 2.5316
c 0
b 0
f 0
eloc 52
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
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) {
0 ignored issues
show
Duplication introduced by
This code seems to be duplicated across 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...
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