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 RecordHandlerFactory |
||
17 | { |
||
18 | /** @var RecordQueryBuilder */ |
||
19 | protected $recordQueryBuilder; |
||
20 | |||
21 | /** @var PlayerDb */ |
||
22 | protected $playerDb; |
||
23 | |||
24 | /** @var string */ |
||
25 | protected $ordering; |
||
26 | |||
27 | /** @var ConfigInterface */ |
||
28 | protected $nbRecords; |
||
29 | |||
30 | /** @var string */ |
||
31 | protected $className; |
||
32 | |||
33 | /** |
||
34 | * RecordHandlerFactory constructor. |
||
35 | * |
||
36 | * @param RecordQueryBuilder $recordQueryBuilder |
||
37 | * @param PlayerDb $playerDb |
||
38 | * @param string $ordering |
||
39 | * @param ConfigInterface $nbRecords |
||
40 | * @param string $className |
||
41 | */ |
||
42 | 1 | View Code Duplication | public function __construct( |
55 | |||
56 | |||
57 | 1 | public function create() |
|
68 | |||
69 | } |
||
70 |
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.