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 |
||
25 | class DateTimeFieldMapper implements FieldMapper |
||
26 | { |
||
27 | use GuardInvalidArgumentsForExifTrait; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | private $validKeys = [ |
||
33 | 'system:filemodifydate', |
||
34 | 'composite:subsecdatetimeoriginal', |
||
35 | 'composite:subsecmodifydate', |
||
36 | 'exififd:datetimeoriginal', |
||
37 | 'exififd:createdate', |
||
38 | 'ifd0:modifydate', |
||
39 | ]; |
||
40 | |||
41 | /** |
||
42 | * Getter for validKeys |
||
43 | * |
||
44 | * @return array |
||
45 | */ |
||
46 | public function getValidKeys() |
||
50 | |||
51 | /** |
||
52 | * Setter for validKeys |
||
53 | * |
||
54 | * @param array $validKeys |
||
55 | */ |
||
56 | public function setValidKeys(array $validKeys) |
||
60 | |||
61 | /** |
||
62 | * {@inheritDoc} |
||
63 | */ |
||
64 | public function getSupportedFields() |
||
70 | |||
71 | /** |
||
72 | * {@inheritDoc} |
||
73 | */ |
||
74 | View Code Duplication | public function mapField($field, array $input, &$output) |
|
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.