Completed
Push — master ( cf7247...7c3177 )
by Lars
04:07
created

Kint_Parsers_ClassStatics::_parse()   C

Complexity

Conditions 8
Paths 15

Size

Total Lines 50
Code Lines 32

Duplication

Lines 12
Ratio 24 %

Importance

Changes 1
Bugs 0 Features 0
Metric Value
c 1
b 0
f 0
dl 12
loc 50
rs 6.3636
cc 8
eloc 32
nc 15
nop 1
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
  protected function _parse(&$variable)
18
  {
19
    if (!is_object($variable)) {
20
      return false;
21
    }
22
23
    $extendedValue = array();
24
25
    $reflection = new \ReflectionClass($variable);
26
    // first show static values
27
    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
    }
48
49
    foreach ($reflection->getConstants() as $constant => $val) {
50
      $output = KintParser::factory($val, $constant);
51
52
      $output->access = 'constant';
53
      $output->operator = '::';
54
      $extendedValue[] = $output;
55
    }
56
57
    if (empty($extendedValue)) {
58
      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
}