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 |
||
21 | class RclKaraokeRowMapper implements RowMapperInterface |
||
22 | { |
||
23 | |||
24 | const INPUT_FIELD_ARTIST = 'artist'; |
||
25 | const INPUT_FIELD_TITLE = 'title'; |
||
26 | // const INPUT_FIELD_HAS_HARMONY = 'hasHarmony'; |
||
27 | // const INPUT_FIELD_HAS_KEYS = 'hasKeys'; |
||
28 | // const INPUT_FIELD_SOURCE = 'source'; |
||
29 | // const INPUT_FIELD_IN_RB3 = 'inRb3'; |
||
30 | // const INPUT_FIELD_IN_RB4 = 'inRb4'; |
||
31 | const INPUT_FIELD_DURATION_MMSS = 'duration_mmss'; |
||
32 | const INPUT_FIELD_DURATION = 'duration'; |
||
33 | |||
34 | /** |
||
35 | * Column map for input file |
||
36 | * |
||
37 | * @var string[] |
||
38 | */ |
||
39 | protected $fileFields = [ |
||
40 | 'B' => self::INPUT_FIELD_ARTIST, |
||
41 | 'C' => self::INPUT_FIELD_TITLE, |
||
42 | // 'D' => self::INPUT_FIELD_HAS_HARMONY, |
||
|
|||
43 | // 'E' => self::INPUT_FIELD_HAS_KEYS, |
||
44 | // 'I' => self::INPUT_FIELD_SOURCE, |
||
45 | // 'F' => self::INPUT_FIELD_IN_RB3, |
||
46 | // 'G' => self::INPUT_FIELD_IN_RB4, |
||
47 | 'H' => self::INPUT_FIELD_DURATION_MMSS, |
||
48 | ]; |
||
49 | |||
50 | protected $fieldLookup = []; |
||
51 | |||
52 | /** |
||
53 | * @var AbstractSql |
||
54 | */ |
||
55 | protected $dataStore; |
||
56 | |||
57 | /** |
||
58 | * @var Instrument |
||
59 | */ |
||
60 | protected $vocals; |
||
61 | |||
62 | /** |
||
63 | * @var Platform |
||
64 | */ |
||
65 | protected $platform; |
||
66 | |||
67 | /** |
||
68 | * @var Platform |
||
69 | */ |
||
70 | protected $source; |
||
71 | |||
72 | /** |
||
73 | * RclRowMapper constructor. |
||
74 | * @param $dataStore |
||
75 | */ |
||
76 | public function __construct(AbstractSql $dataStore) |
||
81 | |||
82 | /** |
||
83 | * Get formatter name for interface / selection |
||
84 | * |
||
85 | * @return string |
||
86 | */ |
||
87 | public function getFormatterName() |
||
91 | |||
92 | /** |
||
93 | * Initialise the RowMapper |
||
94 | * |
||
95 | * @return void |
||
96 | */ |
||
97 | public function init() |
||
111 | |||
112 | /** |
||
113 | * Store a single spreadsheet row |
||
114 | * |
||
115 | * @param array $row Character-indexed flattened DB row |
||
116 | * @return bool True on success |
||
117 | * @throws \Doctrine\DBAL\Exception\InvalidArgumentException |
||
118 | */ |
||
119 | public function storeRawRow(array $row) |
||
144 | |||
145 | /** |
||
146 | * Get short name for form keys, CLI etc |
||
147 | * |
||
148 | * @return string |
||
149 | */ |
||
150 | public function getShortName() |
||
154 | } |
||
155 |
Sometimes obsolete code just ends up commented out instead of removed. In this case it is better to remove the code once you have checked you do not need it.
The code might also have been commented out for debugging purposes. In this case it is vital that someone uncomments it again or your project may behave in very unexpected ways in production.
This check looks for comments that seem to be mostly valid code and reports them.