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 |
||
| 38 | class Exporter implements ExporterInterface |
||
| 39 | { |
||
| 40 | |||
| 41 | /** |
||
| 42 | * The exporter configuration. |
||
| 43 | * |
||
| 44 | * @var \Goodby\CSV\Export\Standard\ExporterConfig |
||
| 45 | */ |
||
| 46 | private $config; |
||
| 47 | |||
| 48 | /** |
||
| 49 | * The number of rows found in the header. |
||
| 50 | * |
||
| 51 | * @var int |
||
| 52 | */ |
||
| 53 | private $rowConsistency = null; |
||
| 54 | |||
| 55 | /** |
||
| 56 | * Query whether or not strict mode is activated or not. |
||
| 57 | * |
||
| 58 | * @var boolean |
||
| 59 | */ |
||
| 60 | private $strict = true; |
||
| 61 | |||
| 62 | /** |
||
| 63 | * Initialize the instance with the passed configuration. |
||
| 64 | * |
||
| 65 | * @param \Goodby\CSV\Export\Standard\ExporterConfig $config The exporter configuration |
||
| 66 | */ |
||
| 67 | public function __construct(ExporterConfig $config) |
||
| 71 | |||
| 72 | /** |
||
| 73 | * Disable strict mode. |
||
| 74 | * |
||
| 75 | * @return void |
||
| 76 | */ |
||
| 77 | public function unstrict() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * Query whether or not strict mode has been activated. |
||
| 84 | * |
||
| 85 | * @return boolean TRUE if the strict mode has NOT been activated, else FALSE |
||
| 86 | */ |
||
| 87 | private function isNotStrict() |
||
| 91 | |||
| 92 | /** |
||
| 93 | * Export data as CSV file. |
||
| 94 | * |
||
| 95 | * @param string $filename The filename to export to |
||
| 96 | * @param array $rows The rows to export |
||
| 97 | * |
||
| 98 | * @return void |
||
| 99 | * @throws \Goodby\CSV\Export\Protocol\Exception\IOException |
||
| 100 | */ |
||
| 101 | public function export($filename, $rows) |
||
| 148 | |||
| 149 | /** |
||
| 150 | * Reset the interpreter. |
||
| 151 | * |
||
| 152 | * @return void |
||
| 153 | */ |
||
| 154 | public function reset() |
||
| 158 | |||
| 159 | /** |
||
| 160 | * Check if the column count is consistent with comparing other rows. |
||
| 161 | * |
||
| 162 | * @param array $row The row to check consistency for |
||
| 163 | * |
||
| 164 | * @return void |
||
| 165 | * @throws \Goodby\CSV\Export\Standard\Exception\StrictViolationException Is thrown, if row consistency check fails |
||
| 166 | */ |
||
| 167 | View Code Duplication | private function checkRowConsistency(array $row) |
|
| 191 | } |
||
| 192 |