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 |
||
| 9 | class Marker extends Model_Base { |
||
| 10 | |||
| 11 | /** |
||
| 12 | * @var string |
||
| 13 | */ |
||
| 14 | protected $_address; |
||
| 15 | |||
| 16 | /** |
||
| 17 | * @var Geocoder |
||
| 18 | */ |
||
| 19 | protected $_geocoder; |
||
| 20 | |||
| 21 | /** |
||
| 22 | * @var Info_Window |
||
| 23 | */ |
||
| 24 | protected $_info_window; |
||
| 25 | |||
| 26 | /** |
||
| 27 | * @var Marker_Label |
||
| 28 | */ |
||
| 29 | protected $_label; |
||
| 30 | |||
| 31 | /** |
||
| 32 | * @var double |
||
| 33 | */ |
||
| 34 | protected $_latitude = null; |
||
| 35 | |||
| 36 | /** |
||
| 37 | * @var double |
||
| 38 | */ |
||
| 39 | protected $_longitude; |
||
| 40 | |||
| 41 | /** |
||
| 42 | * @var Location|\WP_Error |
||
| 43 | */ |
||
| 44 | protected $_location; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * @var string |
||
| 48 | */ |
||
| 49 | protected $_title; |
||
| 50 | |||
| 51 | /** |
||
| 52 | * @var array |
||
| 53 | */ |
||
| 54 | protected $_extra_args = array(); |
||
| 55 | |||
| 56 | /** |
||
| 57 | * Marker_Model constructor. |
||
| 58 | * @param array $args |
||
| 59 | */ |
||
| 60 | 2 | function __construct( $args = array() ) { |
|
| 80 | |||
| 81 | /** |
||
| 82 | * @return Info_Window |
||
| 83 | */ |
||
| 84 | 2 | function info_window() { |
|
| 89 | |||
| 90 | /** |
||
| 91 | * @return Marker_Label |
||
| 92 | */ |
||
| 93 | 1 | function label() { |
|
| 102 | |||
| 103 | /** |
||
| 104 | * @return double |
||
| 105 | */ |
||
| 106 | 1 | View Code Duplication | function latitude() { |
| 113 | |||
| 114 | /** |
||
| 115 | * @return Location|\WP_Error |
||
| 116 | */ |
||
| 117 | 2 | function location() { |
|
| 123 | |||
| 124 | /** |
||
| 125 | * @return double |
||
| 126 | */ |
||
| 127 | 1 | View Code Duplication | function longitude() { |
| 134 | |||
| 135 | /** |
||
| 136 | * Get the position of this marker. An array with key/value pairs of lat and lng. |
||
| 137 | * |
||
| 138 | * @return array |
||
| 139 | */ |
||
| 140 | 1 | function position() { |
|
| 145 | |||
| 146 | /** |
||
| 147 | * @return string |
||
| 148 | */ |
||
| 149 | 1 | function title() { |
|
| 152 | |||
| 153 | /** |
||
| 154 | * @param array $args |
||
| 155 | * @return array |
||
| 156 | */ |
||
| 157 | 1 | function marker_args( $args = array() ) { |
|
| 170 | |||
| 171 | /** |
||
| 172 | * @return Geocoder |
||
| 173 | */ |
||
| 174 | 2 | protected function _geocoder() { |
|
| 181 | |||
| 182 | } |
||
| 183 |
Adding explicit visibility (
private,protected, orpublic) is generally recommend to communicate to other developers how, and from where this method is intended to be used.