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 Returning extends File implements ReturningInterface |
||
| 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 | * Initialize and return a new instance. |
||
| 29 | * |
||
| 30 | * @param string $path path of returning file |
||
| 31 | * @param \SmartCNAB\Support\Picture $picture |
||
| 32 | */ |
||
| 33 | public function __construct($path, Picture $picture) |
||
| 40 | |||
| 41 | /** |
||
| 42 | * Return all return details. |
||
| 43 | * |
||
| 44 | * @return array |
||
| 45 | */ |
||
| 46 | public function details() |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Return the parsed schema. |
||
| 55 | * |
||
| 56 | * @return array |
||
| 57 | */ |
||
| 58 | public function getSchema() |
||
| 62 | |||
| 63 | /** |
||
| 64 | * Returns the file header. |
||
| 65 | * |
||
| 66 | * @return \StdClass |
||
| 67 | */ |
||
| 68 | public function header() |
||
| 74 | |||
| 75 | /** |
||
| 76 | * Returns the file trailer. |
||
| 77 | * |
||
| 78 | * @return \StdClass |
||
| 79 | */ |
||
| 80 | public function trailer() |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Mapper method for one line parsing. |
||
| 89 | * |
||
| 90 | * @param string $detail |
||
| 91 | * @return \StdClass |
||
| 92 | */ |
||
| 93 | protected function detailMapper($detail) |
||
| 99 | |||
| 100 | /** |
||
| 101 | * Create and returns a new line parse mapper using received parameters. |
||
| 102 | * |
||
| 103 | * @param string $data |
||
| 104 | * @return Closure |
||
| 105 | */ |
||
| 106 | protected function getParseMapper($data) |
||
| 112 | |||
| 113 | /** |
||
| 114 | * Parses a line data received using the schema. |
||
| 115 | * |
||
| 116 | * @param string $data |
||
| 117 | * @param string $type |
||
| 118 | * @return array |
||
| 119 | */ |
||
| 120 | View Code Duplication | protected function parseLine($data, $type = 'detail') |
|
| 129 | } |
||
| 130 |