Kint_Objects_Closure   A
last analyzed

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 15%

Importance

Changes 0
Metric Value
dl 0
loc 49
ccs 3
cts 20
cp 0.15
rs 10
c 0
b 0
f 0
wmc 8
lcom 1
cbo 2

1 Method

Rating   Name   Duplication   Size   Complexity  
C parse() 0 41 8
1
<?php
2
3
namespace kint\parsers\objects;
4
5
use kint\inc\KintObject;
6
use kint\Kint;
7
8
/**
9
 * Class Kint_Objects_Closure
10
 */
11
class Kint_Objects_Closure extends KintObject
12
{
13
  /**
14
   * @param $variable
15
   *
16
   * @return array|bool
17
   */
18 2
  public function parse(&$variable)
19
  {
20 2
    if (!$variable instanceof \Closure) {
21 2
      return false;
22
    }
23
24
    $this->name = 'Closure';
25
    $reflection = new \ReflectionFunction($variable);
26
    $ret = array(
27
        'Parameters' => array(),
28
    );
29
30
    $val = $reflection->getParameters();
31
    if ($val) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $val of type ReflectionParameter[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
32
      foreach ($val as $parameter) {
33
        // todo http://php.net/manual/en/class.reflectionparameter.php
34
        $ret['Parameters'][] = $parameter->name;
35
      }
36
37
    }
38
39
    $val = $reflection->getStaticVariables();
40
    if ($val) {
0 ignored issues
show
Bug Best Practice introduced by
The expression $val of type string[] is implicitly converted to a boolean; are you sure this is intended? If so, consider using ! empty($expr) instead to make it clear that you intend to check for an array without elements.

This check marks implicit conversions of arrays to boolean values in a comparison. While in PHP an empty array is considered to be equal (but not identical) to false, this is not always apparent.

Consider making the comparison explicit by using empty(..) or ! empty(...) instead.

Loading history...
41
      $ret['Uses'] = $val;
42
    }
43
44
    if (
45
        method_exists($reflection, 'getClousureThis')
46
        &&
47
        $val = $reflection->getClosureThis()
48
    ) {
49
      $ret['Uses']['$this'] = $val;
50
    }
51
52
    $val = $reflection->getFileName();
53
    if ($val) {
54
      $this->value = Kint::shortenPath($val) . ':' . $reflection->getStartLine();
55
    }
56
57
    return $ret;
58
  }
59
}
60