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 |
||
20 | class UnderscoredClassNamespacePrefix implements NamingStrategy |
||
21 | { |
||
22 | /** |
||
23 | * @var int |
||
24 | */ |
||
25 | protected $case = CASE_LOWER; |
||
26 | |||
27 | /** |
||
28 | * @var bool |
||
29 | */ |
||
30 | protected $joinTableFieldSuffix; |
||
31 | |||
32 | /** |
||
33 | * @var array |
||
34 | */ |
||
35 | protected $whitelist; |
||
36 | |||
37 | /** |
||
38 | * @var array |
||
39 | */ |
||
40 | protected $blacklist; |
||
41 | |||
42 | /** |
||
43 | * @var array |
||
44 | */ |
||
45 | protected $map; |
||
46 | |||
47 | 20 | public function __construct(array $configuration = array()) |
|
73 | |||
74 | /** |
||
75 | * {@inheritdoc} |
||
76 | */ |
||
77 | 12 | View Code Duplication | public function classToTableName($className) |
87 | |||
88 | /** |
||
89 | * {@inheritdoc} |
||
90 | */ |
||
91 | 4 | public function propertyToColumnName($propertyName, $className = null) |
|
95 | |||
96 | /** |
||
97 | * {@inheritdoc} |
||
98 | */ |
||
99 | 2 | public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null) |
|
103 | |||
104 | /** |
||
105 | * {@inheritdoc} |
||
106 | */ |
||
107 | 5 | public function referenceColumnName() |
|
111 | |||
112 | /** |
||
113 | * {@inheritdoc} |
||
114 | */ |
||
115 | 2 | public function joinColumnName($propertyName, $className = null) |
|
119 | |||
120 | /** |
||
121 | * {@inheritdoc} |
||
122 | */ |
||
123 | 3 | View Code Duplication | public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) |
132 | |||
133 | /** |
||
134 | * {@inheritdoc} |
||
135 | */ |
||
136 | 2 | public function joinKeyColumnName($entityName, $referencedColumnName = null) |
|
141 | |||
142 | /** |
||
143 | * Get prefix for table from map. |
||
144 | * |
||
145 | * @param string $className |
||
146 | * @return string |
||
147 | */ |
||
148 | 12 | protected function getTableNamePrefix($className) |
|
176 | |||
177 | /** |
||
178 | * Build underscore version of given string. |
||
179 | * |
||
180 | * @param string $string |
||
181 | * @return string |
||
182 | */ |
||
183 | 18 | View Code Duplication | protected function underscore($string) |
193 | } |
||
194 |
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.