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 |
||
| 5 | use Nickcheek\USPSLookup\Service\Address; |
||
| 6 | use Nickcheek\USPSLookup\Service\Price; |
||
| 7 | use Nickcheek\USPSLookup\Service\Tracking; |
||
| 8 | use Nickcheek\USPSLookup\Service\Pickup; |
||
| 9 | |||
| 10 | |||
| 11 | class USPSLookup |
||
| 12 | { |
||
| 13 | protected static $user; |
||
| 14 | protected static $service = 'http://production.shippingapis.com/ShippingAPI.dll?API='; |
||
| 15 | |||
| 16 | public function __construct($user = '') |
||
| 23 | |||
| 24 | public function Address() |
||
| 28 | |||
| 29 | public function Tracking() |
||
| 33 | |||
| 34 | public function Price() |
||
| 38 | |||
| 39 | public function Pickup() |
||
| 43 | |||
| 44 | } |
||
| 45 |