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 |
||
31 | View Code Duplication | class ServerVariableTransformer extends TransformerAbstract |
|
|
|||
32 | { |
||
33 | /** |
||
34 | * List of resources that can be included. |
||
35 | * |
||
36 | * @var array |
||
37 | */ |
||
38 | protected $availableIncludes = ['parent']; |
||
39 | |||
40 | /** |
||
41 | * The Illuminate Request object if provided. |
||
42 | * |
||
43 | * @var \Illuminate\Http\Request|bool |
||
44 | */ |
||
45 | protected $request; |
||
46 | |||
47 | /** |
||
48 | * Setup request object for transformer. |
||
49 | * |
||
50 | * @param \Illuminate\Http\Request|bool $request |
||
51 | * @return void |
||
52 | */ |
||
53 | public function __construct($request = false) |
||
61 | |||
62 | /** |
||
63 | * Return a generic transformed server variable array. |
||
64 | * |
||
65 | * @return array |
||
66 | */ |
||
67 | public function transform(ServerVariable $variable) |
||
71 | |||
72 | /** |
||
73 | * Return the parent service variable data. |
||
74 | * |
||
75 | * @return \Leauge\Fractal\Resource\Item |
||
76 | */ |
||
77 | public function includeParent(ServerVariable $variable) |
||
85 | } |
||
86 |
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.