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 |
||
16 | class JsonResponseHandler extends Handler |
||
17 | { |
||
18 | /** |
||
19 | * @var bool |
||
20 | */ |
||
21 | private $returnFrames = false; |
||
22 | |||
23 | /** |
||
24 | * @var bool |
||
25 | */ |
||
26 | private $jsonApi = false; |
||
27 | |||
28 | /** |
||
29 | * Returns errors[[]] instead of error[] to be in compliance with the json:api spec |
||
30 | * @param bool $jsonApi Default is false |
||
31 | * @return static |
||
32 | */ |
||
33 | public function setJsonApi($jsonApi = false) |
||
38 | |||
39 | /** |
||
40 | * @param bool|null $returnFrames |
||
41 | * @return bool|static |
||
42 | */ |
||
43 | 3 | View Code Duplication | public function addTraceToOutput($returnFrames = null) |
52 | |||
53 | /** |
||
54 | * @return int |
||
55 | */ |
||
56 | 3 | public function handle() |
|
80 | |||
81 | /** |
||
82 | * @return string |
||
83 | */ |
||
84 | public function contentType() |
||
88 | } |
||
89 |
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.