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()) { |
|
|
|
|
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
|
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
|
|
|
} |
56
|
|
|
|
57
|
1 |
|
if (empty($extendedValue)) { |
58
|
1 |
|
return false; |
59
|
|
|
} |
60
|
|
|
|
61
|
|
|
$this->value = $extendedValue; |
|
|
|
|
62
|
|
|
$this->type = 'Static class properties'; |
63
|
|
|
$this->size = count($extendedValue); |
64
|
|
|
|
65
|
|
|
return true; |
66
|
|
|
} |
67
|
|
|
} |
68
|
|
|
|
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.