Complex classes like VideoPress_Video often do a lot of different things. To break such a class down, we need to identify a cohesive component within that class. A common approach to find such a component is to look for fields/methods that share the same prefixes, or suffixes. You can also have a look at the cohesion graph to spot any un-connected, or weakly-connected components.
Once you have determined the fields that belong together, you can apply the Extract Class refactoring. If the component makes sense as a sub-class, Extract Subclass is also a candidate, and is often faster.
While breaking up the class, it is a good idea to analyze how other classes use VideoPress_Video, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 6 | class VideoPress_Video { |
||
| 7 | public $version = 3; |
||
| 8 | |||
| 9 | /** |
||
| 10 | * Manifest version returned by remote service. |
||
| 11 | * |
||
| 12 | * @var string |
||
| 13 | * @since 1.3 |
||
| 14 | */ |
||
| 15 | const manifest_version = '1.5'; |
||
|
|
|||
| 16 | |||
| 17 | /** |
||
| 18 | * Expiration of the video expressed in Unix time |
||
| 19 | * |
||
| 20 | * @var int |
||
| 21 | * @since 1.3 |
||
| 22 | */ |
||
| 23 | public $expires; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * VideoPress unique identifier |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | * @since 1.3 |
||
| 30 | */ |
||
| 31 | public $guid; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * WordPress.com blog identifier |
||
| 35 | * |
||
| 36 | * @var int |
||
| 37 | * @since 1.5 |
||
| 38 | */ |
||
| 39 | public $blog_id; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Remote blog attachment identifier |
||
| 43 | * |
||
| 44 | * @var int |
||
| 45 | * @since 1.5 |
||
| 46 | */ |
||
| 47 | public $post_id; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * Maximum desired width. |
||
| 51 | * |
||
| 52 | * @var int |
||
| 53 | * @since 1.3 |
||
| 54 | */ |
||
| 55 | public $maxwidth; |
||
| 56 | |||
| 57 | /** |
||
| 58 | * Video width calculated based on original video dimensions and the requested maxwidth |
||
| 59 | * |
||
| 60 | * @var int |
||
| 61 | * @since 1.3 |
||
| 62 | */ |
||
| 63 | public $calculated_width; |
||
| 64 | |||
| 65 | /** |
||
| 66 | * Video height calculated based on original video dimensions and the requested maxwidth |
||
| 67 | * |
||
| 68 | * @var int |
||
| 69 | * @since 1.3 |
||
| 70 | */ |
||
| 71 | public $calculated_height; |
||
| 72 | |||
| 73 | /** |
||
| 74 | * Video title |
||
| 75 | * |
||
| 76 | * @var string |
||
| 77 | * @since 1.3 |
||
| 78 | */ |
||
| 79 | public $title; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * Video description |
||
| 83 | * |
||
| 84 | * @var string |
||
| 85 | * @since 4.4 |
||
| 86 | */ |
||
| 87 | public $description; |
||
| 88 | |||
| 89 | /** |
||
| 90 | * Directionality of title text. ltr or rtl |
||
| 91 | * |
||
| 92 | * @var string |
||
| 93 | * @since 1.3 |
||
| 94 | */ |
||
| 95 | public $text_direction; |
||
| 96 | |||
| 97 | /** |
||
| 98 | * Text and audio language as ISO 639-2 language code |
||
| 99 | * |
||
| 100 | * @var string |
||
| 101 | * @since 1.3 |
||
| 102 | */ |
||
| 103 | public $language; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * Video duration in whole seconds |
||
| 107 | * |
||
| 108 | * @var int |
||
| 109 | * @since 1.3 |
||
| 110 | */ |
||
| 111 | public $duration; |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Recommended minimum age of the viewer. |
||
| 115 | * |
||
| 116 | * @var int |
||
| 117 | * @since 1.3 |
||
| 118 | */ |
||
| 119 | public $age_rating; |
||
| 120 | |||
| 121 | /** |
||
| 122 | * Video author has restricted video embedding or sharing |
||
| 123 | * |
||
| 124 | * @var bool |
||
| 125 | * @since 1.3 |
||
| 126 | */ |
||
| 127 | public $restricted_embed; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * Poster frame image URI for the given video guid and calculated dimensions. |
||
| 131 | * |
||
| 132 | * @var string |
||
| 133 | * @since 1.3 |
||
| 134 | */ |
||
| 135 | public $poster_frame_uri; |
||
| 136 | |||
| 137 | /** |
||
| 138 | * Video files associated with the given guid for the calculated dimensions. |
||
| 139 | * |
||
| 140 | * @var stdClass |
||
| 141 | * @since 1.3 |
||
| 142 | */ |
||
| 143 | public $videos; |
||
| 144 | |||
| 145 | /** |
||
| 146 | * Video player information |
||
| 147 | * |
||
| 148 | * @var stdClass |
||
| 149 | * @since 1.3 |
||
| 150 | */ |
||
| 151 | public $players; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * Video player skinning preferences including background color and watermark |
||
| 155 | * |
||
| 156 | * @var array |
||
| 157 | * @since 1.5 |
||
| 158 | */ |
||
| 159 | public $skin; |
||
| 160 | |||
| 161 | /** |
||
| 162 | * Closed captions if available for the given video. Associative array of ISO 639-2 language code and a WebVTT URI |
||
| 163 | * |
||
| 164 | * @var array |
||
| 165 | * @since 1.5 |
||
| 166 | */ |
||
| 167 | public $captions; |
||
| 168 | |||
| 169 | /** |
||
| 170 | * Setup the object. |
||
| 171 | * Request video information from VideoPress servers and process the response. |
||
| 172 | * |
||
| 173 | * @since 1.3 |
||
| 174 | * @var string $guid VideoPress unique identifier |
||
| 175 | * @var int $maxwidth maximum requested video width. final width and height are calculated on VideoPress servers based on the aspect ratio of the original video upload. |
||
| 176 | */ |
||
| 177 | public function __construct( $guid, $maxwidth = 640 ) { |
||
| 256 | |||
| 257 | /** |
||
| 258 | * Convert an Expires HTTP header value into Unix time for use in WP Cache |
||
| 259 | * |
||
| 260 | * @since 1.3 |
||
| 261 | * @var string $expires_header |
||
| 262 | * @return int|bool Unix time or false |
||
| 263 | */ |
||
| 264 | public static function calculate_expiration( $expires_header ) { |
||
| 282 | |||
| 283 | /** |
||
| 284 | * Extract the site's host domain for statistics and comparison against an allowed site list in the case of restricted embeds. |
||
| 285 | * |
||
| 286 | * @since 1.2 |
||
| 287 | * @param string $url absolute URL |
||
| 288 | * @return bool|string host component of the URL, or false if none found |
||
| 289 | */ |
||
| 290 | public static function hostname( $url ) { |
||
| 293 | |||
| 294 | |||
| 295 | /** |
||
| 296 | * Request data from WordPress.com for the given guid, maxwidth, and calculated blog hostname. |
||
| 297 | * |
||
| 298 | * @since 1.3 |
||
| 299 | * @return stdClass|WP_Error parsed JSON response or WP_Error if request unsuccessful |
||
| 300 | */ |
||
| 301 | private function get_data() { |
||
| 344 | } |
||
| 345 |