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 |
||
13 | abstract class EES_Shortcode extends EE_Base { |
||
14 | |||
15 | /** |
||
16 | * @protected public |
||
17 | * @var array $_attributes |
||
18 | */ |
||
19 | protected $_attributes = array(); |
||
20 | |||
21 | |||
22 | |||
23 | /** |
||
24 | * class constructor - should ONLY be instantiated by EE_Front_Controller |
||
25 | */ |
||
26 | final public function __construct() |
||
34 | |||
35 | |||
36 | |||
37 | /** |
||
38 | * run - initial shortcode module setup called during "parse_request" hook by |
||
39 | * \EE_Front_Controller::_initialize_shortcodes() IF this shortcode is going to execute during this request ! |
||
40 | * It may also get called by \EES_Shortcode::fallback_shortcode_processor() if the shortcode is being implemented |
||
41 | * by a theme or plugin in a non-standard way. |
||
42 | * Basically this method is primarily used for loading resources and assets like CSS or JS |
||
43 | * that will be required by the shortcode when it is actually processed. |
||
44 | * Please note that assets may not load if the fallback_shortcode_processor() is being used. |
||
45 | * |
||
46 | * @access public |
||
47 | * @param WP $WP |
||
48 | * @return void |
||
49 | */ |
||
50 | public abstract function run( WP $WP ); |
||
51 | |||
52 | |||
53 | |||
54 | /** |
||
55 | * process_shortcode |
||
56 | * this method is the callback function for the actual shortcode, and is what runs when WP encounters the shortcode within the_content |
||
57 | * |
||
58 | * @access public |
||
59 | * @param array $attributes |
||
60 | * @return mixed |
||
61 | */ |
||
62 | public abstract function process_shortcode( $attributes = array() ); |
||
63 | |||
64 | |||
65 | |||
66 | /** |
||
67 | * instance - returns instance of child class object |
||
68 | * |
||
69 | * @access public |
||
70 | * @param string $shortcode_class |
||
71 | * @return \EES_Shortcode |
||
72 | */ |
||
73 | final public static function instance( $shortcode_class = null ) { |
||
86 | |||
87 | |||
88 | |||
89 | |||
90 | /** |
||
91 | * fallback_shortcode_processor - create instance and call process_shortcode |
||
92 | * NOTE: shortcode may not function perfectly dues to missing assets, but it's better than not having things work at all |
||
93 | * |
||
94 | * @access public |
||
95 | * @param $attributes |
||
96 | * @return mixed |
||
97 | */ |
||
98 | final public static function fallback_shortcode_processor( $attributes ) { |
||
119 | |||
120 | |||
121 | |||
122 | |||
123 | /** |
||
124 | * invalid_shortcode_processor - used in cases where we know the shortcode is invalid, most likely due to a deactivated addon, and simply returns an empty string |
||
125 | * |
||
126 | * @access public |
||
127 | * @param $attributes |
||
128 | * @return string |
||
129 | */ |
||
130 | final public static function invalid_shortcode_processor( $attributes ) { |
||
133 | |||
134 | |||
135 | |||
136 | |||
137 | |||
138 | /** |
||
139 | * Performs basic sanitization on shortcode attributes |
||
140 | * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
||
141 | * most attributes will by default be sanitized using the sanitize_text_field() function. |
||
142 | * This can be overridden by supplying an array for the $custom_sanitization param, |
||
143 | * where keys match keys in your attributes array, |
||
144 | * and values represent the sanitization function you wish to be applied to that attribute. |
||
145 | * So for example, if you had an integer attribute named "event_id" |
||
146 | * that you wanted to be sanitized using absint(), |
||
147 | * then you would pass the following for your $custom_sanitization array: |
||
148 | * array('event_id' => 'absint') |
||
149 | * all other attributes would be sanitized using the defaults in the switch statement below |
||
150 | * |
||
151 | * @param array $attributes |
||
152 | * @param array $custom_sanitization |
||
153 | * @return array |
||
154 | */ |
||
155 | public static function sanitize_attributes(array $attributes, $custom_sanitization = array()) |
||
192 | |||
193 | |||
194 | } |
||
195 | // End of file EES_Shortcode.shortcode.php |
||
196 | // Location: /shortcodes/EES_Shortcode.shortcode.php |
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.