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 |
||
| 22 | class XmlAuthorizationRequest extends XmlRequest |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | protected $optionalParameters = [ |
||
| 28 | 'reqtype', |
||
| 29 | 'uppCustomerIpAddress' |
||
| 30 | ]; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @var string |
||
| 34 | */ |
||
| 35 | protected $apiEndpoint = 'XML_authorize.jsp'; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var string |
||
| 39 | */ |
||
| 40 | protected $serviceName = 'authorizationService'; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var int |
||
| 44 | */ |
||
| 45 | protected $serviceVersion = 3; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @return array |
||
| 49 | */ |
||
| 50 | public function getData() |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @param $data |
||
| 79 | * @return XmlAuthorizationResponse |
||
| 80 | */ |
||
| 81 | protected function createResponse($data) |
||
| 85 | } |
||
| 86 |
Instead of super-globals, we recommend to explicitly inject the dependencies of your class. This makes your code less dependent on global state and it becomes generally more testable: