Kint_Objects_SplFileInfo   A
last analyzed

Complexity

Total Complexity 25

Size/Duplication

Total Lines 81
Duplicated Lines 30.86 %

Coupling/Cohesion

Components 1
Dependencies 1

Test Coverage

Coverage 8.51%

Importance

Changes 0
Metric Value
dl 25
loc 81
ccs 4
cts 47
cp 0.0851
rs 10
c 0
b 0
f 0
wmc 25
lcom 1
cbo 1

1 Method

Rating   Name   Duplication   Size   Complexity  
F parse() 25 73 25

How to fix   Duplicated Code   

Duplicated Code

Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.

Common duplication problems, and corresponding solutions are:

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