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 |
||
| 36 | class WuBookManager |
||
| 37 | { |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var string |
||
| 41 | */ |
||
| 42 | const ENDPOINT = 'https://wubook.net/xrws/'; |
||
| 43 | |||
| 44 | /** |
||
| 45 | * @var array |
||
| 46 | */ |
||
| 47 | private $config; |
||
| 48 | |||
| 49 | /** |
||
| 50 | * @var Illuminate\Cache\Repository |
||
| 51 | */ |
||
| 52 | private $cache; |
||
| 53 | |||
| 54 | /** |
||
| 55 | * Create a new WuBook Instance. |
||
| 56 | * |
||
| 57 | * @param Repository $config |
||
| 58 | * @throws WuBookException |
||
| 59 | */ |
||
| 60 | public function __construct(Repository $config) |
||
| 77 | |||
| 78 | /** |
||
| 79 | * Auth API |
||
| 80 | * |
||
| 81 | * @return IlGala\LaravelWubook\Api\WuBookAuth |
||
| 82 | */ |
||
| 83 | View Code Duplication | public function auth() |
|
| 90 | |||
| 91 | /** |
||
| 92 | * Availability API |
||
| 93 | * |
||
| 94 | * @param string $token |
||
| 95 | * @return IlGala\LaravelWubook\Api\WuBookAvailability |
||
| 96 | */ |
||
| 97 | View Code Duplication | public function availability($token = null) |
|
| 104 | |||
| 105 | /** |
||
| 106 | * Cancellation polices API |
||
| 107 | * |
||
| 108 | * @param string $token |
||
| 109 | * @return IlGala\LaravelWubook\Api\WuBookCancellationPolicies |
||
| 110 | */ |
||
| 111 | public function cancellation_policies($token = null) |
||
| 117 | |||
| 118 | /** |
||
| 119 | * Channel manager API |
||
| 120 | * |
||
| 121 | * @param string $token |
||
| 122 | * @return IlGala\LaravelWubook\Api\WuBookChannelManager |
||
| 123 | */ |
||
| 124 | View Code Duplication | public function channel_manager($token = null) |
|
| 131 | |||
| 132 | /** |
||
| 133 | * Corporate function API |
||
| 134 | * |
||
| 135 | * @param string $token |
||
| 136 | * @return IlGala\LaravelWubook\Api\WuBookCorporate |
||
| 137 | */ |
||
| 138 | View Code Duplication | public function corporate_functions($token = null) |
|
| 145 | |||
| 146 | /** |
||
| 147 | * Extra functions API |
||
| 148 | * |
||
| 149 | * @param string $token |
||
| 150 | * @return IlGala\LaravelWubook\Api\WuBookExtras |
||
| 151 | */ |
||
| 152 | View Code Duplication | public function extras($token = null) |
|
| 159 | |||
| 160 | /** |
||
| 161 | * Prices API |
||
| 162 | * |
||
| 163 | * @param string $token |
||
| 164 | * @return IlGala\LaravelWubook\Api\WuBookPrices |
||
| 165 | */ |
||
| 166 | View Code Duplication | public function prices($token = null) |
|
| 173 | |||
| 174 | /** |
||
| 175 | * Reservations API |
||
| 176 | * |
||
| 177 | * @param string $token |
||
| 178 | * @return IlGala\LaravelWubook\Api\WuBookPrices |
||
| 179 | */ |
||
| 180 | View Code Duplication | public function reservations($token = null) |
|
| 187 | |||
| 188 | /** |
||
| 189 | * Restrictions API |
||
| 190 | * |
||
| 191 | * @param string $token |
||
| 192 | * @return IlGala\LaravelWubook\Api\WuBookRestrictions |
||
| 193 | */ |
||
| 194 | View Code Duplication | public function restrictions($token = null) |
|
| 201 | |||
| 202 | /** |
||
| 203 | * Rooms API |
||
| 204 | * |
||
| 205 | * @param string $token |
||
| 206 | * @return IlGala\LaravelWubook\Api\WuBookRooms |
||
| 207 | */ |
||
| 208 | View Code Duplication | public function rooms($token = null) |
|
| 215 | |||
| 216 | /** |
||
| 217 | * Transactions API |
||
| 218 | * |
||
| 219 | * @param string $token |
||
| 220 | * @return IlGala\LaravelWubook\Api\WuBookTransactions |
||
| 221 | */ |
||
| 222 | View Code Duplication | public function transactions($token = null) |
|
| 229 | |||
| 230 | /** |
||
| 231 | * Username getter. |
||
| 232 | * |
||
| 233 | * @return string |
||
| 234 | */ |
||
| 235 | public function get_username() |
||
| 239 | |||
| 240 | /** |
||
| 241 | * Password getter. |
||
| 242 | * |
||
| 243 | * @return string |
||
| 244 | */ |
||
| 245 | public function get_password() |
||
| 249 | |||
| 250 | /** |
||
| 251 | * Provider key getter. |
||
| 252 | * |
||
| 253 | * @return string |
||
| 254 | */ |
||
| 255 | public function get_provider_key() |
||
| 259 | |||
| 260 | /** |
||
| 261 | * Client getter. |
||
| 262 | * |
||
| 263 | * @return PhpXmlRpc\Client |
||
| 264 | */ |
||
| 265 | public function get_client() |
||
| 269 | } |
||
| 270 |
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: