Duplicate code is one of the most pungent code smells. A rule that is often used is to re-structure code once it is duplicated in three or more places.
Common duplication problems, and corresponding solutions are:
Complex classes like SimplePie_Enclosure 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 SimplePie_Enclosure, and based on these observations, apply Extract Interface, too.
| 1 | <?php |
||
| 55 | class SimplePie_Enclosure |
||
| 56 | { |
||
| 57 | /** |
||
| 58 | * @var string |
||
| 59 | * @see get_bitrate() |
||
| 60 | */ |
||
| 61 | var $bitrate; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * @var array |
||
| 65 | * @see get_captions() |
||
| 66 | */ |
||
| 67 | var $captions; |
||
| 68 | |||
| 69 | /** |
||
| 70 | * @var array |
||
| 71 | * @see get_categories() |
||
| 72 | */ |
||
| 73 | var $categories; |
||
| 74 | |||
| 75 | /** |
||
| 76 | * @var int |
||
| 77 | * @see get_channels() |
||
| 78 | */ |
||
| 79 | var $channels; |
||
| 80 | |||
| 81 | /** |
||
| 82 | * @var SimplePie_Copyright |
||
| 83 | * @see get_copyright() |
||
| 84 | */ |
||
| 85 | var $copyright; |
||
| 86 | |||
| 87 | /** |
||
| 88 | * @var array |
||
| 89 | * @see get_credits() |
||
| 90 | */ |
||
| 91 | var $credits; |
||
| 92 | |||
| 93 | /** |
||
| 94 | * @var string |
||
| 95 | * @see get_description() |
||
| 96 | */ |
||
| 97 | var $description; |
||
| 98 | |||
| 99 | /** |
||
| 100 | * @var int |
||
| 101 | * @see get_duration() |
||
| 102 | */ |
||
| 103 | var $duration; |
||
| 104 | |||
| 105 | /** |
||
| 106 | * @var string |
||
| 107 | * @see get_expression() |
||
| 108 | */ |
||
| 109 | var $expression; |
||
| 110 | |||
| 111 | /** |
||
| 112 | * @var string |
||
| 113 | * @see get_framerate() |
||
| 114 | */ |
||
| 115 | var $framerate; |
||
| 116 | |||
| 117 | /** |
||
| 118 | * @var string |
||
| 119 | * @see get_handler() |
||
| 120 | */ |
||
| 121 | var $handler; |
||
| 122 | |||
| 123 | /** |
||
| 124 | * @var array |
||
| 125 | * @see get_hashes() |
||
| 126 | */ |
||
| 127 | var $hashes; |
||
| 128 | |||
| 129 | /** |
||
| 130 | * @var string |
||
| 131 | * @see get_height() |
||
| 132 | */ |
||
| 133 | var $height; |
||
| 134 | |||
| 135 | /** |
||
| 136 | * @deprecated |
||
| 137 | * @var null |
||
| 138 | */ |
||
| 139 | var $javascript; |
||
| 140 | |||
| 141 | /** |
||
| 142 | * @var array |
||
| 143 | * @see get_keywords() |
||
| 144 | */ |
||
| 145 | var $keywords; |
||
| 146 | |||
| 147 | /** |
||
| 148 | * @var string |
||
| 149 | * @see get_language() |
||
| 150 | */ |
||
| 151 | var $lang; |
||
| 152 | |||
| 153 | /** |
||
| 154 | * @var string |
||
| 155 | * @see get_length() |
||
| 156 | */ |
||
| 157 | var $length; |
||
| 158 | |||
| 159 | /** |
||
| 160 | * @var string |
||
| 161 | * @see get_link() |
||
| 162 | */ |
||
| 163 | var $link; |
||
| 164 | |||
| 165 | /** |
||
| 166 | * @var string |
||
| 167 | * @see get_medium() |
||
| 168 | */ |
||
| 169 | var $medium; |
||
| 170 | |||
| 171 | /** |
||
| 172 | * @var string |
||
| 173 | * @see get_player() |
||
| 174 | */ |
||
| 175 | var $player; |
||
| 176 | |||
| 177 | /** |
||
| 178 | * @var array |
||
| 179 | * @see get_ratings() |
||
| 180 | */ |
||
| 181 | var $ratings; |
||
| 182 | |||
| 183 | /** |
||
| 184 | * @var array |
||
| 185 | * @see get_restrictions() |
||
| 186 | */ |
||
| 187 | var $restrictions; |
||
| 188 | |||
| 189 | /** |
||
| 190 | * @var string |
||
| 191 | * @see get_sampling_rate() |
||
| 192 | */ |
||
| 193 | var $samplingrate; |
||
| 194 | |||
| 195 | /** |
||
| 196 | * @var array |
||
| 197 | * @see get_thumbnails() |
||
| 198 | */ |
||
| 199 | var $thumbnails; |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @var string |
||
| 203 | * @see get_title() |
||
| 204 | */ |
||
| 205 | var $title; |
||
| 206 | |||
| 207 | /** |
||
| 208 | * @var string |
||
| 209 | * @see get_type() |
||
| 210 | */ |
||
| 211 | var $type; |
||
| 212 | |||
| 213 | /** |
||
| 214 | * @var string |
||
| 215 | * @see get_width() |
||
| 216 | */ |
||
| 217 | var $width; |
||
| 218 | |||
| 219 | /** |
||
| 220 | * Constructor, used to input the data |
||
| 221 | * |
||
| 222 | * For documentation on all the parameters, see the corresponding |
||
| 223 | * properties and their accessors |
||
| 224 | * |
||
| 225 | * @uses idna_convert If available, this will convert an IDN |
||
| 226 | */ |
||
| 227 | public function __construct($link = null, $type = null, $length = null, $javascript = null, $bitrate = null, $captions = null, $categories = null, $channels = null, $copyright = null, $credits = null, $description = null, $duration = null, $expression = null, $framerate = null, $hashes = null, $height = null, $keywords = null, $lang = null, $medium = null, $player = null, $ratings = null, $restrictions = null, $samplingrate = null, $thumbnails = null, $title = null, $width = null) |
||
| 263 | |||
| 264 | /** |
||
| 265 | * String-ified version |
||
| 266 | * |
||
| 267 | * @return string |
||
| 268 | */ |
||
| 269 | public function __toString() |
||
| 274 | |||
| 275 | /** |
||
| 276 | * Get the bitrate |
||
| 277 | * |
||
| 278 | * @return string|null |
||
| 279 | */ |
||
| 280 | public function get_bitrate() |
||
| 291 | |||
| 292 | /** |
||
| 293 | * Get a single caption |
||
| 294 | * |
||
| 295 | * @param int $key |
||
| 296 | * @return SimplePie_Caption|null |
||
| 297 | */ |
||
| 298 | public function get_caption($key = 0) |
||
| 310 | |||
| 311 | /** |
||
| 312 | * Get all captions |
||
| 313 | * |
||
| 314 | * @return array|null Array of {@see SimplePie_Caption} objects |
||
| 315 | */ |
||
| 316 | public function get_captions() |
||
| 327 | |||
| 328 | /** |
||
| 329 | * Get a single category |
||
| 330 | * |
||
| 331 | * @param int $key |
||
| 332 | * @return SimplePie_Category|null |
||
| 333 | */ |
||
| 334 | View Code Duplication | public function get_category($key = 0) |
|
| 346 | |||
| 347 | /** |
||
| 348 | * Get all categories |
||
| 349 | * |
||
| 350 | * @return array|null Array of {@see SimplePie_Category} objects |
||
| 351 | */ |
||
| 352 | public function get_categories() |
||
| 363 | |||
| 364 | /** |
||
| 365 | * Get the number of audio channels |
||
| 366 | * |
||
| 367 | * @return int|null |
||
| 368 | */ |
||
| 369 | public function get_channels() |
||
| 380 | |||
| 381 | /** |
||
| 382 | * Get the copyright information |
||
| 383 | * |
||
| 384 | * @return SimplePie_Copyright|null |
||
| 385 | */ |
||
| 386 | public function get_copyright() |
||
| 397 | |||
| 398 | /** |
||
| 399 | * Get a single credit |
||
| 400 | * |
||
| 401 | * @param int $key |
||
| 402 | * @return SimplePie_Credit|null |
||
| 403 | */ |
||
| 404 | public function get_credit($key = 0) |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Get all credits |
||
| 419 | * |
||
| 420 | * @return array|null Array of {@see SimplePie_Credit} objects |
||
| 421 | */ |
||
| 422 | public function get_credits() |
||
| 433 | |||
| 434 | /** |
||
| 435 | * Get the description of the enclosure |
||
| 436 | * |
||
| 437 | * @return string|null |
||
| 438 | */ |
||
| 439 | public function get_description() |
||
| 450 | |||
| 451 | /** |
||
| 452 | * Get the duration of the enclosure |
||
| 453 | * |
||
| 454 | * @param string $convert Convert seconds into hh:mm:ss |
||
| 455 | * @return string|int|null 'hh:mm:ss' string if `$convert` was specified, otherwise integer (or null if none found) |
||
| 456 | */ |
||
| 457 | public function get_duration($convert = false) |
||
| 476 | |||
| 477 | /** |
||
| 478 | * Get the expression |
||
| 479 | * |
||
| 480 | * @return string Probably one of 'sample', 'full', 'nonstop', 'clip'. Defaults to 'full' |
||
| 481 | */ |
||
| 482 | public function get_expression() |
||
| 493 | |||
| 494 | /** |
||
| 495 | * Get the file extension |
||
| 496 | * |
||
| 497 | * @return string|null |
||
| 498 | */ |
||
| 499 | public function get_extension() |
||
| 511 | |||
| 512 | /** |
||
| 513 | * Get the framerate (in frames-per-second) |
||
| 514 | * |
||
| 515 | * @return string|null |
||
| 516 | */ |
||
| 517 | public function get_framerate() |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Get the preferred handler |
||
| 531 | * |
||
| 532 | * @return string|null One of 'flash', 'fmedia', 'quicktime', 'wmedia', 'mp3' |
||
| 533 | */ |
||
| 534 | public function get_handler() |
||
| 538 | |||
| 539 | /** |
||
| 540 | * Get a single hash |
||
| 541 | * |
||
| 542 | * @link http://www.rssboard.org/media-rss#media-hash |
||
| 543 | * @param int $key |
||
| 544 | * @return string|null Hash as per `media:hash`, prefixed with "$algo:" |
||
| 545 | */ |
||
| 546 | public function get_hash($key = 0) |
||
| 558 | |||
| 559 | /** |
||
| 560 | * Get all credits |
||
| 561 | * |
||
| 562 | * @return array|null Array of strings, see {@see get_hash()} |
||
| 563 | */ |
||
| 564 | public function get_hashes() |
||
| 575 | |||
| 576 | /** |
||
| 577 | * Get the height |
||
| 578 | * |
||
| 579 | * @return string|null |
||
| 580 | */ |
||
| 581 | public function get_height() |
||
| 592 | |||
| 593 | /** |
||
| 594 | * Get the language |
||
| 595 | * |
||
| 596 | * @link http://tools.ietf.org/html/rfc3066 |
||
| 597 | * @return string|null Language code as per RFC 3066 |
||
| 598 | */ |
||
| 599 | public function get_language() |
||
| 610 | |||
| 611 | /** |
||
| 612 | * Get a single keyword |
||
| 613 | * |
||
| 614 | * @param int $key |
||
| 615 | * @return string|null |
||
| 616 | */ |
||
| 617 | public function get_keyword($key = 0) |
||
| 629 | |||
| 630 | /** |
||
| 631 | * Get all keywords |
||
| 632 | * |
||
| 633 | * @return array|null Array of strings |
||
| 634 | */ |
||
| 635 | public function get_keywords() |
||
| 646 | |||
| 647 | /** |
||
| 648 | * Get length |
||
| 649 | * |
||
| 650 | * @return float Length in bytes |
||
| 651 | */ |
||
| 652 | public function get_length() |
||
| 663 | |||
| 664 | /** |
||
| 665 | * Get the URL |
||
| 666 | * |
||
| 667 | * @return string|null |
||
| 668 | */ |
||
| 669 | public function get_link() |
||
| 680 | |||
| 681 | /** |
||
| 682 | * Get the medium |
||
| 683 | * |
||
| 684 | * @link http://www.rssboard.org/media-rss#media-content |
||
| 685 | * @return string|null Should be one of 'image', 'audio', 'video', 'document', 'executable' |
||
| 686 | */ |
||
| 687 | public function get_medium() |
||
| 698 | |||
| 699 | /** |
||
| 700 | * Get the player URL |
||
| 701 | * |
||
| 702 | * Typically the same as {@see get_permalink()} |
||
| 703 | * @return string|null Player URL |
||
| 704 | */ |
||
| 705 | public function get_player() |
||
| 716 | |||
| 717 | /** |
||
| 718 | * Get a single rating |
||
| 719 | * |
||
| 720 | * @param int $key |
||
| 721 | * @return SimplePie_Rating|null |
||
| 722 | */ |
||
| 723 | public function get_rating($key = 0) |
||
| 735 | |||
| 736 | /** |
||
| 737 | * Get all ratings |
||
| 738 | * |
||
| 739 | * @return array|null Array of {@see SimplePie_Rating} objects |
||
| 740 | */ |
||
| 741 | public function get_ratings() |
||
| 752 | |||
| 753 | /** |
||
| 754 | * Get a single restriction |
||
| 755 | * |
||
| 756 | * @param int $key |
||
| 757 | * @return SimplePie_Restriction|null |
||
| 758 | */ |
||
| 759 | public function get_restriction($key = 0) |
||
| 771 | |||
| 772 | /** |
||
| 773 | * Get all restrictions |
||
| 774 | * |
||
| 775 | * @return array|null Array of {@see SimplePie_Restriction} objects |
||
| 776 | */ |
||
| 777 | public function get_restrictions() |
||
| 788 | |||
| 789 | /** |
||
| 790 | * Get the sampling rate (in kHz) |
||
| 791 | * |
||
| 792 | * @return string|null |
||
| 793 | */ |
||
| 794 | public function get_sampling_rate() |
||
| 805 | |||
| 806 | /** |
||
| 807 | * Get the file size (in MiB) |
||
| 808 | * |
||
| 809 | * @return float|null File size in mebibytes (1048 bytes) |
||
| 810 | */ |
||
| 811 | public function get_size() |
||
| 823 | |||
| 824 | /** |
||
| 825 | * Get a single thumbnail |
||
| 826 | * |
||
| 827 | * @param int $key |
||
| 828 | * @return string|null Thumbnail URL |
||
| 829 | */ |
||
| 830 | public function get_thumbnail($key = 0) |
||
| 842 | |||
| 843 | /** |
||
| 844 | * Get all thumbnails |
||
| 845 | * |
||
| 846 | * @return array|null Array of thumbnail URLs |
||
| 847 | */ |
||
| 848 | public function get_thumbnails() |
||
| 859 | |||
| 860 | /** |
||
| 861 | * Get the title |
||
| 862 | * |
||
| 863 | * @return string|null |
||
| 864 | */ |
||
| 865 | public function get_title() |
||
| 876 | |||
| 877 | /** |
||
| 878 | * Get mimetype of the enclosure |
||
| 879 | * |
||
| 880 | * @see get_real_type() |
||
| 881 | * @return string|null MIME type |
||
| 882 | */ |
||
| 883 | public function get_type() |
||
| 894 | |||
| 895 | /** |
||
| 896 | * Get the width |
||
| 897 | * |
||
| 898 | * @return string|null |
||
| 899 | */ |
||
| 900 | public function get_width() |
||
| 911 | |||
| 912 | /** |
||
| 913 | * Embed the enclosure using `<embed>` |
||
| 914 | * |
||
| 915 | * @deprecated Use the second parameter to {@see embed} instead |
||
| 916 | * |
||
| 917 | * @param array|string $options See first paramter to {@see embed} |
||
| 918 | * @return string HTML string to output |
||
| 919 | */ |
||
| 920 | public function native_embed($options='') |
||
| 924 | |||
| 925 | /** |
||
| 926 | * Embed the enclosure using Javascript |
||
| 927 | * |
||
| 928 | * `$options` is an array or comma-separated key:value string, with the |
||
| 929 | * following properties: |
||
| 930 | * |
||
| 931 | * - `alt` (string): Alternate content for when an end-user does not have |
||
| 932 | * the appropriate handler installed or when a file type is |
||
| 933 | * unsupported. Can be any text or HTML. Defaults to blank. |
||
| 934 | * - `altclass` (string): If a file type is unsupported, the end-user will |
||
| 935 | * see the alt text (above) linked directly to the content. That link |
||
| 936 | * will have this value as its class name. Defaults to blank. |
||
| 937 | * - `audio` (string): This is an image that should be used as a |
||
| 938 | * placeholder for audio files before they're loaded (QuickTime-only). |
||
| 939 | * Can be any relative or absolute URL. Defaults to blank. |
||
| 940 | * - `bgcolor` (string): The background color for the media, if not |
||
| 941 | * already transparent. Defaults to `#ffffff`. |
||
| 942 | * - `height` (integer): The height of the embedded media. Accepts any |
||
| 943 | * numeric pixel value (such as `360`) or `auto`. Defaults to `auto`, |
||
| 944 | * and it is recommended that you use this default. |
||
| 945 | * - `loop` (boolean): Do you want the media to loop when its done? |
||
| 946 | * Defaults to `false`. |
||
| 947 | * - `mediaplayer` (string): The location of the included |
||
| 948 | * `mediaplayer.swf` file. This allows for the playback of Flash Video |
||
| 949 | * (`.flv`) files, and is the default handler for non-Odeo MP3's. |
||
| 950 | * Defaults to blank. |
||
| 951 | * - `video` (string): This is an image that should be used as a |
||
| 952 | * placeholder for video files before they're loaded (QuickTime-only). |
||
| 953 | * Can be any relative or absolute URL. Defaults to blank. |
||
| 954 | * - `width` (integer): The width of the embedded media. Accepts any |
||
| 955 | * numeric pixel value (such as `480`) or `auto`. Defaults to `auto`, |
||
| 956 | * and it is recommended that you use this default. |
||
| 957 | * - `widescreen` (boolean): Is the enclosure widescreen or standard? |
||
| 958 | * This applies only to video enclosures, and will automatically resize |
||
| 959 | * the content appropriately. Defaults to `false`, implying 4:3 mode. |
||
| 960 | * |
||
| 961 | * Note: Non-widescreen (4:3) mode with `width` and `height` set to `auto` |
||
| 962 | * will default to 480x360 video resolution. Widescreen (16:9) mode with |
||
| 963 | * `width` and `height` set to `auto` will default to 480x270 video resolution. |
||
| 964 | * |
||
| 965 | * @todo If the dimensions for media:content are defined, use them when width/height are set to 'auto'. |
||
| 966 | * @param array|string $options Comma-separated key:value list, or array |
||
| 967 | * @param bool $native Use `<embed>` |
||
| 968 | * @return string HTML string to output |
||
| 969 | */ |
||
| 970 | public function embed($options = '', $native = false) |
||
| 1193 | |||
| 1194 | /** |
||
| 1195 | * Get the real media type |
||
| 1196 | * |
||
| 1197 | * Often, feeds lie to us, necessitating a bit of deeper inspection. This |
||
| 1198 | * converts types to their canonical representations based on the file |
||
| 1199 | * extension |
||
| 1200 | * |
||
| 1201 | * @see get_type() |
||
| 1202 | * @param bool $find_handler Internal use only, use {@see get_handler()} instead |
||
| 1203 | * @return string MIME type |
||
| 1204 | */ |
||
| 1205 | public function get_real_type($find_handler = false) |
||
| 1379 | } |
||
| 1380 | |||
| 1381 |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.