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 |
||
35 | class PhptalRenderer extends Renderer |
||
36 | { |
||
37 | /** |
||
38 | * @constant string The directory inside the cache dir where templates will |
||
39 | * be stored in compiled form. |
||
40 | */ |
||
41 | const COMPILE_DIR = 'templates'; |
||
42 | |||
43 | /** |
||
44 | * @constant string The subdirectory inside the compile dir where templates |
||
45 | * will be stored in compiled form. |
||
46 | */ |
||
47 | const COMPILE_SUBDIR = 'phptal'; |
||
48 | |||
49 | /** |
||
50 | * @var string A string with the default template file extension, |
||
51 | * including the dot. |
||
52 | */ |
||
53 | protected $defaultExtension = '.tal'; |
||
54 | |||
55 | /** |
||
56 | * @var PHPTAL PHPTAL template engine. |
||
57 | */ |
||
58 | protected $phptal = null; |
||
59 | |||
60 | /** |
||
61 | * Pre-serialization callback. |
||
62 | * |
||
63 | * Excludes the PHPTAL instance to prevent excessive serialization load. |
||
64 | * |
||
65 | * @author David Zülke <[email protected]> |
||
66 | * @since 0.11.0 |
||
67 | */ |
||
68 | public function __sleep() |
||
74 | |||
75 | /** |
||
76 | * Create an instance of PHPTAL and initialize it correctly. |
||
77 | * |
||
78 | * @return PHPTAL The PHPTAL instance. |
||
79 | * |
||
80 | * @author David Zülke <[email protected]> |
||
81 | * @since 1.0.2 |
||
82 | */ |
||
83 | protected function createEngineInstance() |
||
112 | |||
113 | /** |
||
114 | * Retrieve the PHPTAL instance |
||
115 | * |
||
116 | * @return PHPTAL A PHPTAL instance. |
||
117 | * |
||
118 | * @author David Zülke <[email protected]> |
||
119 | * @author Benjamin Muskalla <[email protected]> |
||
120 | * @since 0.11.0 |
||
121 | */ |
||
122 | protected function getEngine() |
||
132 | |||
133 | /** |
||
134 | * Render the presentation and return the result. |
||
135 | * |
||
136 | * @param TemplateLayer $layer The template layer to render. |
||
137 | * @param array $attributes The template variables. |
||
138 | * @param array $slots The slots. |
||
139 | * @param array $moreAssigns Associative array of additional assigns. |
||
140 | * |
||
141 | * @return string A rendered result. |
||
142 | * |
||
143 | * @author David Zülke <[email protected]> |
||
144 | * @author Benjamin Muskalla <[email protected]> |
||
145 | * @since 0.11.0 |
||
146 | */ |
||
147 | public function render(TemplateLayer $layer, array &$attributes = array(), array &$slots = array(), array &$moreAssigns = array()) |
||
174 | } |
||
175 |
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.