Conditions | 5 |
Paths | 1 |
Total Lines | 29 |
Lines | 0 |
Ratio | 0 % |
Tests | 0 |
CRAP Score | 30 |
Changes | 0 |
1 | <?php |
||
47 | public function __getToArrayCallBack() |
||
48 | { |
||
49 | return function ($subject) { |
||
50 | static::$__depth++; |
||
51 | |||
52 | if ($subject instanceof Arrayable) { |
||
53 | $subject = $subject->toArray(); |
||
54 | } |
||
55 | |||
56 | if (is_object($subject)) { |
||
57 | $subject = get_object_vars($subject); |
||
58 | } |
||
59 | |||
60 | if (is_array($subject)) { |
||
61 | if (static::$__depth <= static::$__maxDepth) { |
||
62 | $subject = array_map( |
||
63 | $this->__getToArrayCallBack(), |
||
64 | $subject |
||
65 | ); |
||
66 | } else { |
||
67 | $subject = null; |
||
68 | } |
||
69 | } |
||
70 | |||
71 | static::$__depth--; |
||
72 | |||
73 | return $subject; |
||
74 | }; |
||
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: