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 |
||
9 | abstract class Transformer extends TransformerAbstract |
||
10 | { |
||
11 | /** |
||
12 | * Returns the includes that are available for eager loading. |
||
13 | * |
||
14 | * @param array|string $requestedIncludes Array of csv string |
||
15 | * |
||
16 | * @return $this |
||
17 | */ |
||
18 | public function getEagerLoads($requestedIncludes) |
||
31 | |||
32 | /** |
||
33 | * Create a new item resource object. |
||
34 | * |
||
35 | * @param mixed $data |
||
36 | * @param TransformerAbstract|callable $transformer |
||
37 | * @param string $resourceKey |
||
38 | * |
||
39 | * @return Item |
||
40 | */ |
||
41 | protected function item($data, $transformer, $resourceKey = null) |
||
49 | } |
||
50 |
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.