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 |
||
| 30 | class FeFactory implements FeFactoryInterface |
||
| 31 | { |
||
| 32 | /** |
||
| 33 | * @var FeBuilderInteface |
||
| 34 | */ |
||
| 35 | private $builder; |
||
| 36 | |||
| 37 | /** |
||
| 38 | * @var SignedXml |
||
| 39 | */ |
||
| 40 | private $signer; |
||
| 41 | |||
| 42 | /** |
||
| 43 | * @var ZipFactory |
||
| 44 | */ |
||
| 45 | private $zipper; |
||
| 46 | |||
| 47 | /** |
||
| 48 | * @var WsSunatInterface |
||
| 49 | */ |
||
| 50 | private $sender; |
||
| 51 | |||
| 52 | /** |
||
| 53 | * Ultimo xml generado. |
||
| 54 | * |
||
| 55 | * @var string |
||
| 56 | */ |
||
| 57 | private $lastXml; |
||
| 58 | /** |
||
| 59 | * @var Company |
||
| 60 | */ |
||
| 61 | private $company; |
||
| 62 | |||
| 63 | /** |
||
| 64 | * FeFactory constructor. |
||
| 65 | */ |
||
| 66 | 32 | public function __construct() |
|
| 73 | |||
| 74 | /** |
||
| 75 | * @param Invoice $invoice |
||
| 76 | * @return BillResult |
||
| 77 | */ |
||
| 78 | 6 | public function sendInvoice(Invoice $invoice) |
|
| 85 | |||
| 86 | /** |
||
| 87 | * Envia una Nota de Credito o Debito. |
||
| 88 | * |
||
| 89 | * @param Note $note |
||
| 90 | * @return BillResult |
||
| 91 | */ |
||
| 92 | 12 | public function sendNote(Note $note) |
|
| 99 | |||
| 100 | /** |
||
| 101 | * Envia un resumen diario de Boletas. |
||
| 102 | * |
||
| 103 | * @param Summary $summary |
||
| 104 | * @return SummaryResult |
||
| 105 | */ |
||
| 106 | 6 | public function sendResumen(Summary $summary) |
|
| 113 | |||
| 114 | /** |
||
| 115 | * Envia una comunicacion de Baja. |
||
| 116 | * |
||
| 117 | * @param Voided $voided |
||
| 118 | * @return SummaryResult |
||
| 119 | */ |
||
| 120 | 6 | public function sendBaja(Voided $voided) |
|
| 127 | |||
| 128 | /** |
||
| 129 | * Get Status by Ticket. |
||
| 130 | * |
||
| 131 | * @param string $ticket |
||
| 132 | * @return StatusResult |
||
| 133 | */ |
||
| 134 | 2 | public function getStatus($ticket) |
|
| 138 | |||
| 139 | /** |
||
| 140 | * @param $company |
||
| 141 | * @return $this |
||
| 142 | */ |
||
| 143 | 32 | public function setCompany(Company $company) |
|
| 150 | |||
| 151 | /** |
||
| 152 | * @param array $params |
||
| 153 | */ |
||
| 154 | 32 | public function setParameters($params) |
|
| 166 | |||
| 167 | /** |
||
| 168 | * Get Last XML Signed. |
||
| 169 | * |
||
| 170 | * @return string |
||
| 171 | */ |
||
| 172 | 10 | public function getLastXml() |
|
| 176 | |||
| 177 | /** |
||
| 178 | * @param array $ws |
||
| 179 | */ |
||
| 180 | 32 | private function setWsParams($ws) |
|
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $xml |
||
| 193 | * @param string $filename |
||
| 194 | * @return BillResult |
||
| 195 | */ |
||
| 196 | 12 | View Code Duplication | private function getBillResult($xml, $filename) |
| 203 | |||
| 204 | /** |
||
| 205 | * @param string $xml |
||
| 206 | * @param string $filename |
||
| 207 | * @return SummaryResult |
||
| 208 | */ |
||
| 209 | 8 | View Code Duplication | private function getSummaryResult($xml, $filename) |
| 216 | |||
| 217 | /** |
||
| 218 | * @param string $xml |
||
| 219 | * @return string |
||
| 220 | */ |
||
| 221 | 20 | private function getXmmlSigned($xml) |
|
| 225 | } |
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.