Conditions | 5 |
Paths | 1 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 15 |
CRAP Score | 5 |
Changes | 0 |
1 | <?php |
||
47 | 1 | public function __getToArrayCallBack() |
|
48 | { |
||
49 | return function ($subject) { |
||
50 | 1 | static::$__depth++; |
|
51 | |||
52 | 1 | if ($subject instanceof Arrayable) { |
|
53 | 1 | $subject = $subject->toArray(); |
|
54 | } |
||
55 | |||
56 | 1 | if (is_object($subject)) { |
|
57 | 1 | $subject = get_object_vars($subject); |
|
58 | } |
||
59 | |||
60 | 1 | if (is_array($subject)) { |
|
61 | 1 | if (static::$__depth <= static::$__maxDepth) { |
|
62 | 1 | $subject = array_map( |
|
63 | 1 | $this->__getToArrayCallBack(), |
|
64 | 1 | $subject |
|
65 | ); |
||
66 | } else { |
||
67 | 1 | $subject = null; |
|
68 | } |
||
69 | } |
||
70 | |||
71 | 1 | static::$__depth--; |
|
72 | |||
73 | 1 | return $subject; |
|
74 | 1 | }; |
|
75 | } |
||
76 | } |
||
77 |
Let’s assume you have a class which uses late-static binding:
The code above will run fine in your PHP runtime. However, if you now create a sub-class and call the
getSomeVariable()
on that sub-class, you will receive a runtime error:In the case above, it makes sense to update
SomeClass
to useself
instead: