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 UnderscoredBundleNamePrefix implements NamingStrategy |
||
18 | { |
||
19 | /** |
||
20 | * @var int |
||
21 | */ |
||
22 | protected $case = CASE_LOWER; |
||
23 | |||
24 | /** |
||
25 | * @var bool |
||
26 | */ |
||
27 | protected $joinTableFieldSuffix; |
||
28 | |||
29 | /** |
||
30 | * @var array |
||
31 | */ |
||
32 | protected $map; |
||
33 | |||
34 | 17 | public function __construct(KernelInterface $kernel, array $options = array()) |
|
53 | |||
54 | /** |
||
55 | * {@inheritdoc} |
||
56 | */ |
||
57 | 9 | public function classToTableName($className) |
|
67 | |||
68 | /** |
||
69 | * {@inheritdoc} |
||
70 | */ |
||
71 | 4 | public function propertyToColumnName($propertyName, $className = null) |
|
75 | |||
76 | /** |
||
77 | * {@inheritdoc} |
||
78 | */ |
||
79 | 2 | public function embeddedFieldToColumnName($propertyName, $embeddedColumnName, $className = null, $embeddedClassName = null) |
|
83 | |||
84 | /** |
||
85 | * {@inheritdoc} |
||
86 | */ |
||
87 | 5 | public function referenceColumnName() |
|
91 | |||
92 | /** |
||
93 | * {@inheritdoc} |
||
94 | */ |
||
95 | 2 | public function joinColumnName($propertyName, $className = null) |
|
99 | |||
100 | /** |
||
101 | * {@inheritdoc} |
||
102 | */ |
||
103 | 3 | public function joinTableName($sourceEntity, $targetEntity, $propertyName = null) |
|
112 | |||
113 | /** |
||
114 | * {@inheritdoc} |
||
115 | */ |
||
116 | 2 | public function joinKeyColumnName($entityName, $referencedColumnName = null) |
|
121 | |||
122 | /** |
||
123 | * Get bundle naming map. |
||
124 | * |
||
125 | * @param KernelInterface $kernel |
||
126 | * @param array $configuration |
||
127 | * |
||
128 | * @return array |
||
129 | */ |
||
130 | 16 | private function getNamingMap(KernelInterface $kernel, array $configuration) |
|
167 | |||
168 | /** |
||
169 | * Get prefix for table from map. |
||
170 | * |
||
171 | * @param string $className |
||
172 | * @return string |
||
173 | */ |
||
174 | 9 | protected function getTableNamePrefix($className) |
|
187 | |||
188 | |||
189 | /** |
||
190 | * Build underscore version of given string. |
||
191 | * |
||
192 | * @param string $string |
||
193 | * @return string |
||
194 | */ |
||
195 | 16 | protected function underscore($string) |
|
205 | } |
||
206 |
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.