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 |
||
22 | class Nexcessnet_Turpentine_Model_Varnish_Configurator_Version2 |
||
23 | extends Nexcessnet_Turpentine_Model_Varnish_Configurator_Abstract { |
||
24 | |||
25 | const VCL_TEMPLATE_FILE = 'version-2.vcl'; |
||
26 | const VCL_VERSION = '2'; |
||
27 | |||
28 | |||
29 | /** |
||
30 | * Generate the Varnish 2.1-compatible VCL |
||
31 | * |
||
32 | * @param bool $doClean if true, VCL will be cleaned (whitespaces stripped, etc.) |
||
33 | * @return string |
||
34 | */ |
||
35 | public function generate($doClean = true) { |
||
41 | |||
42 | View Code Duplication | protected function _getAdvancedSessionValidation() { |
|
49 | |||
50 | /** |
||
51 | * Build the list of template variables to apply to the VCL template |
||
52 | * |
||
53 | * @return array |
||
54 | */ |
||
55 | View Code Duplication | protected function _getTemplateVars() { |
|
69 | } |
||
70 |
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.