| Conditions | 12 |
| Paths | 12 |
| Total Lines | 38 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
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 |
||
| 31 | public function wl_after_get_jsonld( $jsonld, $post_id, $context ) { |
||
|
|
|||
| 32 | if ( 0 === count( $jsonld ) ) { |
||
| 33 | return $jsonld; |
||
| 34 | } |
||
| 35 | $current_item = $jsonld[0]; |
||
| 36 | |||
| 37 | if ( ! array_key_exists( '@type', $current_item ) ) { |
||
| 38 | // Cant determine type return early. |
||
| 39 | return $jsonld; |
||
| 40 | } |
||
| 41 | |||
| 42 | $type = $current_item['@type']; |
||
| 43 | if ( ( is_string( $type ) && $type === 'Article' ) || |
||
| 44 | ( is_array( $type ) && in_array( 'Article', $type ) ) ) { |
||
| 45 | return $jsonld; |
||
| 46 | } |
||
| 47 | |||
| 48 | $videos_jsonld = $this->get_videos_jsonld( $post_id ); |
||
| 49 | if ( 0 === count( $videos_jsonld ) ) { |
||
| 50 | return $jsonld; |
||
| 51 | } |
||
| 52 | |||
| 53 | // check if we have @id in jsonld for first item. |
||
| 54 | $id = array_key_exists( '@id', $current_item ) ? $current_item['@id'] : ''; |
||
| 55 | |||
| 56 | foreach ( $videos_jsonld as &$video_jsonld ) { |
||
| 57 | if ( ! $id) { |
||
| 58 | continue; |
||
| 59 | } |
||
| 60 | if ( ! array_key_exists( 'mentions', $video_jsonld ) ) { |
||
| 61 | $video_jsonld['mentions'] = array( '@id' => $id ); |
||
| 62 | } else { |
||
| 63 | $video_jsonld['mentions'] = array_merge( $video_jsonld['mentions'], array( '@id' => $id ) ); |
||
| 64 | } |
||
| 65 | } |
||
| 66 | |||
| 67 | return array_merge( $jsonld, $videos_jsonld ); |
||
| 68 | } |
||
| 69 | |||
| 178 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.