Completed
Push — master ( 8a340c...157d96 )
by Lars
03:22
created

Kint_Parsers_ClassStatics::_parse()   C

Complexity

Conditions 8
Paths 15

Size

Total Lines 50
Code Lines 32

Duplication

Lines 12
Ratio 24 %

Code Coverage

Tests 11
CRAP Score 27.8145

Importance

Changes 2
Bugs 1 Features 0
Metric Value
c 2
b 1
f 0
dl 12
loc 50
ccs 11
cts 34
cp 0.3235
rs 6.3636
cc 8
eloc 32
nc 15
nop 1
crap 27.8145
1
<?php
2
3
namespace kint\parsers\custom;
4
5
use kint\inc\KintParser;
6
7
/**
8
 * Class Kint_Parsers_ClassStatics
9
 */
10
class Kint_Parsers_ClassStatics extends KintParser
11
{
12
  /**
13
   * @param mixed $variable
14
   *
15
   * @return bool
16
   */
17 1
  protected function _parse(&$variable)
18
  {
19 1
    if (!is_object($variable)) {
20 1
      return false;
21
    }
22
23 1
    $extendedValue = array();
24
25 1
    $reflection = new \ReflectionClass($variable);
26
    // first show static values
27 1
    foreach ($reflection->getProperties(\ReflectionProperty::IS_STATIC) as $property) {
28 View Code Duplication
      if ($property->isPrivate()) {
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...
29
        if (!method_exists($property, 'setAccessible')) {
30
          break;
31
        }
32
        $property->setAccessible(true);
33
        $access = 'private';
34
      } elseif ($property->isProtected()) {
35
        $property->setAccessible(true);
36
        $access = 'protected';
37
      } else {
38
        $access = 'public';
39
      }
40
41
      $_ = $property->getValue();
42
      $output = KintParser::factory($_, '$' . $property->getName());
43
44
      $output->access = $access;
45
      $output->operator = '::';
46
      $extendedValue[] = $output;
47 1
    }
48
49 1
    foreach ($reflection->getConstants() as $constant => $val) {
50
      $output = KintParser::factory($val, $constant);
51
52
      $output->access = 'constant';
53
      $output->operator = '::';
54
      $extendedValue[] = $output;
55 1
    }
56
57 1
    if (empty($extendedValue)) {
58 1
      return false;
59
    }
60
61
    $this->value = $extendedValue;
0 ignored issues
show
Documentation Bug introduced by
It seems like $extendedValue of type array is incompatible with the declared type string of property $value.

Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.

Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..

Loading history...
62
    $this->type = 'Static class properties';
63
    $this->size = count($extendedValue);
64
65
    return true;
66
  }
67
}
68