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 |
||
| 18 | View Code Duplication | class ArrayWalkTransformer extends TransformerAbstract |
|
|
|
|||
| 19 | { |
||
| 20 | /** |
||
| 21 | * Any callable with two argument which returns something |
||
| 22 | * |
||
| 23 | * @var callable |
||
| 24 | */ |
||
| 25 | protected $callable; |
||
| 26 | |||
| 27 | /** |
||
| 28 | * @var mixed |
||
| 29 | */ |
||
| 30 | protected $userdata; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * @param callable $callable Worth nothing to say that the first callback argument should |
||
| 34 | * be a reference if you want anything to append to the record |
||
| 35 | * @param null|mixed $userdata |
||
| 36 | */ |
||
| 37 | public function __construct(callable $callable, $userdata = null) |
||
| 42 | |||
| 43 | /** |
||
| 44 | * Execute the array_map call |
||
| 45 | * |
||
| 46 | * @param mixed $record |
||
| 47 | * |
||
| 48 | * @return mixed |
||
| 49 | */ |
||
| 50 | public function exec($record) |
||
| 60 | } |
||
| 61 |
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.