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 |
||
17 | class RealQuery extends Generic |
||
18 | { |
||
19 | /** @var string Query returned entity class name */ |
||
20 | protected $entityClass; |
||
21 | |||
22 | /** |
||
23 | * Query constructor. |
||
24 | * |
||
25 | * @param Generator $generator |
||
26 | * @param $metadata |
||
27 | */ |
||
28 | View Code Duplication | public function __construct(Generator $generator, $metadata) |
|
36 | |||
37 | /** |
||
38 | * Class uses generation part. |
||
39 | * |
||
40 | * @param RealMetadata $metadata Entity metadata |
||
41 | */ |
||
42 | protected function createUses($metadata) |
||
48 | |||
49 | /** |
||
50 | * Class definition generation part. |
||
51 | * |
||
52 | * @param RealMetadata $metadata Entity metadata |
||
53 | */ |
||
54 | protected function createDefinition($metadata) |
||
64 | |||
65 | /** |
||
66 | * Class static fields generation part. |
||
67 | * |
||
68 | * @param RealMetadata $metadata Entity metadata |
||
69 | */ |
||
70 | protected function createStaticFields($metadata) |
||
80 | |||
81 | /** |
||
82 | * Class methods generation part. |
||
83 | * |
||
84 | * @param RealMetadata $metadata Entity metadata |
||
85 | */ |
||
86 | View Code Duplication | protected function createMethods($metadata) |
|
111 | } |
||
112 | //[PHPCOMPRESSOR(remove,end)] |
||
113 |
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.