| Conditions | 11 |
| Paths | 3 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 10 |
| Ratio | 38.46 % |
| Changes | 2 | ||
| Bugs | 0 | Features | 1 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 34 | private function json_wrap( $any, $skip_assoc = false, $seen_nodes = array() ) { |
||
| 35 | |||
| 36 | if ( ! $skip_assoc && is_array( $any ) && is_string( key( $any ) ) ) { |
||
| 37 | return (object) array( '_PHP_ASSOC' => $this->json_wrap( $any, true ) ); |
||
| 38 | } |
||
| 39 | |||
| 40 | if ( is_array( $any ) || is_object( $any ) ) { |
||
| 41 | foreach ( $any as $k => &$v ) { |
||
| 42 | if ( ( is_array( $v ) || is_object( $v ) ) ) { |
||
| 43 | View Code Duplication | if ( in_array( $v, $seen_nodes, true ) ) { |
|
| 44 | if ( is_object( $any ) ) { |
||
| 45 | unset( $any->{ $k } ); |
||
| 46 | } else { |
||
| 47 | unset( $any[ $k ] ); |
||
| 48 | } |
||
| 49 | continue; |
||
| 50 | } else { |
||
| 51 | $seen_nodes[] = $v; |
||
| 52 | } |
||
| 53 | } |
||
| 54 | $v = $this->json_wrap( $v, false, $seen_nodes ); |
||
| 55 | } |
||
| 56 | } |
||
| 57 | |||
| 58 | return $any; |
||
| 59 | } |
||
| 60 | |||
| 75 |