| Conditions | 5 |
| Paths | 9 |
| Total Lines | 51 |
| 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 |
||
| 120 | public function get_videos_jsonld( $post_id ) { |
||
| 121 | |||
| 122 | $videos = $this->video_storage->get_all_videos( $post_id ); |
||
| 123 | |||
| 124 | $jsonld = array(); |
||
| 125 | |||
| 126 | foreach ( $videos as $video ) { |
||
| 127 | /** |
||
| 128 | * @var $video Video |
||
| 129 | */ |
||
| 130 | $description = $video->description; |
||
| 131 | if ( ! $video->description ) { |
||
| 132 | // If description is empty then use the video title as description |
||
| 133 | $description = $video->name; |
||
| 134 | } |
||
| 135 | $single_jsonld = array( |
||
| 136 | '@context' => 'http://schema.org', |
||
| 137 | '@type' => 'VideoObject', |
||
| 138 | 'name' => $video->name, |
||
| 139 | 'description' => $description, |
||
| 140 | 'contentUrl' => $video->content_url, |
||
| 141 | 'embedUrl' => $video->embed_url, |
||
| 142 | 'uploadDate' => $video->upload_date, |
||
| 143 | 'thumbnailUrl' => $video->thumbnail_urls, |
||
| 144 | 'duration' => $video->duration, |
||
| 145 | ); |
||
| 146 | |||
| 147 | if ( $video->views ) { |
||
| 148 | $single_jsonld['interactionStatistic'] = array( |
||
| 149 | '@type' => 'InteractionCounter', |
||
| 150 | 'interactionType' => array( |
||
| 151 | '@type' => 'http://schema.org/WatchAction' |
||
| 152 | ), |
||
| 153 | 'userInteractionCount' => $video->views |
||
| 154 | ); |
||
| 155 | } |
||
| 156 | |||
| 157 | if ( $video->is_live_video ) { |
||
| 158 | $single_jsonld['publication'] = array( |
||
| 159 | '@type' => 'BroadcastEvent', |
||
| 160 | 'isLiveBroadcast' => true, |
||
| 161 | 'startDate' => $video->live_video_start_date, |
||
| 162 | 'endDate' => $video->live_video_end_date |
||
| 163 | ); |
||
| 164 | } |
||
| 165 | |||
| 166 | $jsonld[] = $single_jsonld; |
||
| 167 | } |
||
| 168 | |||
| 169 | return $jsonld; |
||
| 170 | } |
||
| 171 | |||
| 183 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.