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 SimpleKaraokeRowMapper implements RowMapperInterface |
||
22 | { |
||
23 | |||
24 | const INPUT_FIELD_ARTIST = 'artist'; |
||
25 | const INPUT_FIELD_TITLE = 'title'; |
||
26 | const INPUT_FIELD_DURATION_MMSS = 'duration_mmss'; |
||
27 | const INPUT_FIELD_DURATION = 'duration'; |
||
28 | |||
29 | /** |
||
30 | * Column map for input file |
||
31 | * |
||
32 | * @var string[] |
||
33 | */ |
||
34 | protected $fileFields = [ |
||
35 | 'A' => self::INPUT_FIELD_ARTIST, |
||
36 | 'B' => self::INPUT_FIELD_TITLE, |
||
37 | 'C' => self::INPUT_FIELD_DURATION_MMSS, |
||
38 | ]; |
||
39 | |||
40 | protected $fieldLookup = []; |
||
41 | |||
42 | /** |
||
43 | * @var AbstractSql |
||
44 | */ |
||
45 | protected $dataStore; |
||
46 | |||
47 | /** |
||
48 | * @var Instrument |
||
49 | */ |
||
50 | protected $vocals; |
||
51 | |||
52 | /** |
||
53 | * @var Platform |
||
54 | */ |
||
55 | protected $platform; |
||
56 | |||
57 | /** |
||
58 | * @var Platform |
||
59 | */ |
||
60 | protected $source; |
||
61 | |||
62 | /** |
||
63 | * RclRowMapper constructor. |
||
64 | * @param $dataStore |
||
65 | */ |
||
66 | public function __construct(AbstractSql $dataStore) |
||
71 | |||
72 | /** |
||
73 | * Get formatter name for interface / selection |
||
74 | * |
||
75 | * @return string |
||
76 | */ |
||
77 | public function getFormatterName() |
||
81 | |||
82 | protected function getDefaultPlatformName() |
||
86 | |||
87 | /** |
||
88 | * Initialise the RowMapper |
||
89 | * |
||
90 | * @return void |
||
91 | */ |
||
92 | public function init() |
||
106 | |||
107 | /** |
||
108 | * Store a single spreadsheet row |
||
109 | * |
||
110 | * @param array $row Character-indexed flattened DB row |
||
111 | * @return bool True on success |
||
112 | * @throws \Doctrine\DBAL\Exception\InvalidArgumentException |
||
113 | */ |
||
114 | public function storeRawRow(array $row) |
||
139 | |||
140 | /** |
||
141 | * Get short name for form keys, CLI etc |
||
142 | * |
||
143 | * @return string |
||
144 | */ |
||
145 | public function getShortName() |
||
149 | } |
||
150 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..