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 BaseFactory |
||
| 23 | { |
||
| 24 | /** |
||
| 25 | * @var SignedXml |
||
| 26 | */ |
||
| 27 | protected $signer; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @var ZipFactory |
||
| 31 | */ |
||
| 32 | protected $zipper; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * @var WsSunatInterface |
||
| 36 | */ |
||
| 37 | protected $sender; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Ultimo xml generado. |
||
| 41 | * |
||
| 42 | * @var string |
||
| 43 | */ |
||
| 44 | protected $lastXml; |
||
| 45 | |||
| 46 | /** |
||
| 47 | * BaseFactory constructor. |
||
| 48 | */ |
||
| 49 | 60 | public function __construct() |
|
| 56 | |||
| 57 | /** |
||
| 58 | * @param array $ws |
||
| 59 | */ |
||
| 60 | 60 | protected function setWsParams($ws) |
|
| 70 | |||
| 71 | /** |
||
| 72 | * @param string $xml |
||
| 73 | * @param string $filename |
||
| 74 | * @return BillResult |
||
| 75 | */ |
||
| 76 | 26 | View Code Duplication | protected function getBillResult($xml, $filename) |
| 83 | |||
| 84 | /** |
||
| 85 | * @param string $xml |
||
| 86 | * @param string $filename |
||
| 87 | * @return SummaryResult |
||
| 88 | */ |
||
| 89 | 10 | View Code Duplication | protected function getSummaryResult($xml, $filename) |
| 96 | |||
| 97 | /** |
||
| 98 | * @param string $xml |
||
| 99 | * @return string |
||
| 100 | */ |
||
| 101 | 36 | private function getXmmlSigned($xml) |
|
| 105 | } |
Duplicated code is one of the most pungent code smells. If you need to duplicate the same code in three or more different places, we strongly encourage you to look into extracting the code into a single class or operation.
You can also find more detailed suggestions in the “Code” section of your repository.