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 |
||
| 12 | View Code Duplication | trait ZipTrait |
|
|
|
|||
| 13 | { |
||
| 14 | /** |
||
| 15 | * Returns an iterator where one or more iterables are zipped together |
||
| 16 | * |
||
| 17 | * This function returns a list of tuples, where the i-th tuple contains |
||
| 18 | * the i-th element from each of the argument sequences or iterables. |
||
| 19 | * |
||
| 20 | * The returned list is truncated in length to the length of the |
||
| 21 | * shortest argument sequence. |
||
| 22 | * |
||
| 23 | * > zip([1, 2, 3], ['a', 'b', 'c']) |
||
| 24 | * [1, 'a'] [2, 'b'] [3, 'c'] |
||
| 25 | * |
||
| 26 | * @param array|string|\Iterator $iterable |
||
| 27 | * @param array|string|\Iterator $iterable2 |
||
| 28 | * @return ZipIterator |
||
| 29 | */ |
||
| 30 | 10 | public function zip(/* $iterable, $iterable2, ... */) |
|
| 43 | } |
||
| 44 |
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.