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 |
||
| 11 | class Remittance extends File implements RemittanceInterface |
||
| 12 | { |
||
| 13 | /** |
||
| 14 | * Picture instance. |
||
| 15 | * |
||
| 16 | * @var \SmartCNAB\Support\Picture |
||
| 17 | */ |
||
| 18 | protected $picture; |
||
| 19 | |||
| 20 | /** |
||
| 21 | * Parsed schema. |
||
| 22 | * |
||
| 23 | * @var array |
||
| 24 | */ |
||
| 25 | protected $schema; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * Lines sequential. |
||
| 29 | * |
||
| 30 | * @var integer |
||
| 31 | */ |
||
| 32 | protected $sequential = 0; |
||
| 33 | |||
| 34 | /** |
||
| 35 | * Initialize and return a new instance. |
||
| 36 | * |
||
| 37 | * @param \SmartCNAB\Support\Picture $picture |
||
| 38 | */ |
||
| 39 | public function __construct(Picture $picture) |
||
| 44 | |||
| 45 | /** |
||
| 46 | * Add some detail data for file. |
||
| 47 | * |
||
| 48 | * @param array $data |
||
| 49 | * @return \SmartCNAB\Support\File\Remittance |
||
| 50 | */ |
||
| 51 | public function addDetail(array $data) |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Set data for file header build. |
||
| 62 | * |
||
| 63 | * @param array $data |
||
| 64 | * @return \SmartCNAB\Support\File\Remittance |
||
| 65 | */ |
||
| 66 | public function begin(array $data) |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Ends a file with trailer. |
||
| 77 | * |
||
| 78 | * @return \SmartCNAB\Support\File\Remittance |
||
| 79 | */ |
||
| 80 | public function end() |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Return the parsed schema. |
||
| 92 | * |
||
| 93 | * @return array |
||
| 94 | */ |
||
| 95 | public function getSchema() |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Add some detail data for file. |
||
| 102 | * |
||
| 103 | * @param array $data |
||
| 104 | * @return \SmartCNAB\Support\File\Remittance |
||
| 105 | */ |
||
| 106 | protected function addLine(array $data) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Format the line data received using the schema. |
||
| 115 | * |
||
| 116 | * @param array $data |
||
| 117 | * @param string $type |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | View Code Duplication | protected function formatLine(array $data, $type = 'detail') |
|
| 133 | |||
| 134 | /** |
||
| 135 | * Create and returns a new line format mapper using received parameters. |
||
| 136 | * |
||
| 137 | * @param array $data |
||
| 138 | * @param string $type |
||
| 139 | * @return Closure |
||
| 140 | */ |
||
| 141 | protected function getFormatMapper(array $data, $type) |
||
| 154 | |||
| 155 | /** |
||
| 156 | * Increment and return the data. |
||
| 157 | * |
||
| 158 | * @param array $data |
||
| 159 | * @return array |
||
| 160 | */ |
||
| 161 | protected function increment(array $data) |
||
| 167 | } |
||
| 168 |