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 |
||
| 17 | View Code Duplication | class ArrayReplaceRecursiveTransformer extends TransformerAbstract |
|
|
|
|||
| 18 | { |
||
| 19 | /** |
||
| 20 | * @var array |
||
| 21 | */ |
||
| 22 | protected $default; |
||
| 23 | |||
| 24 | /** |
||
| 25 | * @var array |
||
| 26 | */ |
||
| 27 | protected $override; |
||
| 28 | |||
| 29 | /** |
||
| 30 | * @param array $default An array of the default field values to use, if any |
||
| 31 | * @param array $override An array of the field to always set to the same value, if any |
||
| 32 | */ |
||
| 33 | public function __construct(array $default, array $override = []) |
||
| 38 | |||
| 39 | /** |
||
| 40 | * Set defaults and/or overrides recursively in the record |
||
| 41 | * |
||
| 42 | * @param mixed $record |
||
| 43 | * |
||
| 44 | * @return mixed |
||
| 45 | */ |
||
| 46 | public function exec($record) |
||
| 50 | } |
||
| 51 |
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.