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 |
||
9 | abstract class CompilerFacade extends ValuesCompiler |
||
10 | { |
||
11 | protected static $mixinBlocks = array(); |
||
12 | |||
13 | /** |
||
14 | * Record a closure as a mixin block during execution jade template time. |
||
15 | * |
||
16 | * @param string mixin name |
||
17 | * @param string mixin block treatment |
||
18 | */ |
||
19 | public static function recordMixinBlock($name, $func = null) |
||
26 | |||
27 | /** |
||
28 | * Record a closure as a mixin block during execution jade template time. |
||
29 | * |
||
30 | * @param string mixin name |
||
31 | * @param string mixin block treatment |
||
32 | */ |
||
33 | View Code Duplication | public static function callMixinBlock($name, $attributes = array()) |
|
42 | |||
43 | /** |
||
44 | * Record a closure as a mixin block during execution jade template time |
||
45 | * and propagate variables. |
||
46 | * |
||
47 | * @param string mixin name |
||
48 | * @param &array variables handler propagated from parent scope |
||
49 | * @param string mixin block treatment |
||
50 | */ |
||
51 | View Code Duplication | public static function callMixinBlockWithVars($name, &$varHandler, $attributes = array()) |
|
60 | |||
61 | /** |
||
62 | * End of the record of the mixin block. |
||
63 | * |
||
64 | * @param string mixin name |
||
65 | */ |
||
66 | public static function terminateMixinBlock($name) |
||
72 | |||
73 | /** |
||
74 | * Get property from object. |
||
75 | * |
||
76 | * @param object $object source object |
||
77 | * @param mixed $key key to retrive from the object or the array |
||
78 | * |
||
79 | * @return mixed |
||
80 | */ |
||
81 | public static function getPropertyFromObject($anything, $key) |
||
93 | |||
94 | /** |
||
95 | * Get property from object or entry from array. |
||
96 | * |
||
97 | * @param object|array $anything source |
||
98 | * @param mixed $key key to retrive from the object or the array |
||
99 | * |
||
100 | * @return mixed |
||
101 | */ |
||
102 | public static function getPropertyFromAnything($anything, $key) |
||
113 | |||
114 | /** |
||
115 | * Merge given attributes such as tag attributes with mixin attributes. |
||
116 | * |
||
117 | * @param array $attributes |
||
118 | * @param array $mixinAttributes |
||
119 | * |
||
120 | * @return array |
||
121 | */ |
||
122 | public static function withMixinAttributes($attributes, $mixinAttributes) |
||
138 | |||
139 | /** |
||
140 | * Display a list of attributes with the given quote character in HTML. |
||
141 | * |
||
142 | * @param array $attributes |
||
143 | * @param string $quote |
||
144 | */ |
||
145 | public static function displayAttributes($attributes, $quote, $terse) |
||
159 | |||
160 | /** |
||
161 | * Return true if the given value can be display |
||
162 | * (null or false should not be displayed in the output HTML). |
||
163 | * |
||
164 | * @param $value |
||
165 | * |
||
166 | * @return bool |
||
167 | */ |
||
168 | public static function isDisplayable($value) |
||
172 | } |
||
173 |
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.