Completed
Push — master ( 5d9c5a...0c0414 )
by Lars
03:16
created

Kint_Objects_Closure   A

Complexity

Total Complexity 8

Size/Duplication

Total Lines 49
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 2

Test Coverage

Coverage 10.71%

Importance

Changes 1
Bugs 0 Features 0
Metric Value
wmc 8
c 1
b 0
f 0
lcom 1
cbo 2
dl 0
loc 49
rs 10
ccs 3
cts 28
cp 0.1071

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 1
  public function parse(&$variable)
19
  {
20 1
    if (!$variable instanceof \Closure) {
21 1
      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