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 |
||
| 26 | class FeFactory extends BaseFactory implements FeFactoryInterface |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * @var FeBuilderInteface |
||
| 30 | */ |
||
| 31 | private $builder; |
||
| 32 | |||
| 33 | /** |
||
| 34 | * FeFactory constructor. |
||
| 35 | */ |
||
| 36 | 34 | public function __construct() |
|
| 41 | |||
| 42 | /** |
||
| 43 | * @param Invoice $invoice |
||
| 44 | * @return BillResult |
||
| 45 | */ |
||
| 46 | 8 | public function sendInvoice(Invoice $invoice) |
|
| 53 | |||
| 54 | /** |
||
| 55 | * Envia una Nota de Credito o Debito. |
||
| 56 | * |
||
| 57 | * @param Note $note |
||
| 58 | * @return BillResult |
||
| 59 | */ |
||
| 60 | 12 | public function sendNote(Note $note) |
|
| 67 | |||
| 68 | /** |
||
| 69 | * Envia un resumen diario de Boletas. |
||
| 70 | * |
||
| 71 | * @param Summary $summary |
||
| 72 | * @return SummaryResult |
||
| 73 | */ |
||
| 74 | 6 | public function sendResumen(Summary $summary) |
|
| 81 | |||
| 82 | /** |
||
| 83 | * Envia una comunicacion de Baja. |
||
| 84 | * |
||
| 85 | * @param Voided $voided |
||
| 86 | * @return SummaryResult |
||
| 87 | */ |
||
| 88 | 6 | public function sendBaja(Voided $voided) |
|
| 95 | |||
| 96 | /** |
||
| 97 | * Get Status by Ticket. |
||
| 98 | * |
||
| 99 | * @param string $ticket |
||
| 100 | * @return StatusResult |
||
| 101 | */ |
||
| 102 | 2 | public function getStatus($ticket) |
|
| 106 | |||
| 107 | /** |
||
| 108 | * @param $company |
||
| 109 | * @return $this |
||
| 110 | */ |
||
| 111 | 34 | public function setCompany(Company $company) |
|
| 118 | |||
| 119 | /** |
||
| 120 | * @param array $params |
||
| 121 | */ |
||
| 122 | 34 | View Code Duplication | public function setParameters($params) |
| 134 | |||
| 135 | /** |
||
| 136 | * Get Last XML Signed. |
||
| 137 | * |
||
| 138 | * @return string |
||
| 139 | */ |
||
| 140 | 10 | public function getLastXml() |
|
| 144 | } |
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.