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:
| 1 | <?php |
||
| 20 | class WP_SimplePie_Sanitize_KSES extends SimplePie_Sanitize { |
||
| 21 | |||
| 22 | /** |
||
| 23 | * WordPress SimplePie sanitization using KSES. |
||
| 24 | * |
||
| 25 | * Sanitizes the incoming data, to ensure that it matches the type of data expected, using KSES. |
||
| 26 | * |
||
| 27 | * @since 3.5.0 |
||
| 28 | * @access public |
||
| 29 | * |
||
| 30 | * @param mixed $data The data that needs to be sanitized. |
||
| 31 | * @param integer $type The type of data that it's supposed to be. |
||
| 32 | * @param string $base Optional. The `xml:base` value to use when converting relative |
||
| 33 | * URLs to absolute ones. Default empty. |
||
| 34 | * @return mixed Sanitized data. |
||
| 35 | */ |
||
| 36 | public function sanitize( $data, $type, $base = '' ) { |
||
| 59 | } |
||
| 60 |
In PHP it is possible to write to properties without declaring them. For example, the following is perfectly valid PHP code:
Generally, it is a good practice to explictly declare properties to avoid accidental typos and provide IDE auto-completion: