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 |
||
| 18 | abstract class EspressoShortcode implements ShortcodeInterface |
||
| 19 | { |
||
| 20 | |||
| 21 | /** |
||
| 22 | * transient prefix |
||
| 23 | * |
||
| 24 | * @type string |
||
| 25 | */ |
||
| 26 | const CACHE_TRANSIENT_PREFIX = 'ee_sc_'; |
||
| 27 | |||
| 28 | |||
| 29 | |||
| 30 | /** |
||
| 31 | * enqueues scripts then processes the shortcode |
||
| 32 | * |
||
| 33 | * @param array $attributes |
||
| 34 | * @return string |
||
| 35 | * @throws \EE_Error |
||
| 36 | */ |
||
| 37 | final public function processShortcodeCallback($attributes = array()) |
||
| 50 | |||
| 51 | |||
| 52 | |||
| 53 | /** |
||
| 54 | * If shortcode caching is enabled for the shortcode, |
||
| 55 | * and cached results exist, then that will be returned |
||
| 56 | * else new content will be generated. |
||
| 57 | * If caching is enabled, then the new content will be cached for later. |
||
| 58 | * |
||
| 59 | * @param array $attributes |
||
| 60 | * @return mixed|string |
||
| 61 | * @throws \EE_Error |
||
| 62 | */ |
||
| 63 | private function shortcodeContent(array $attributes) |
||
| 92 | |||
| 93 | |||
| 94 | |||
| 95 | /** |
||
| 96 | * @param array $attributes |
||
| 97 | * @return string |
||
| 98 | * @throws \EE_Error |
||
| 99 | */ |
||
| 100 | private function shortcodeCacheID(array $attributes) |
||
| 113 | |||
| 114 | |||
| 115 | |||
| 116 | /** |
||
| 117 | * array for defining custom attribute sanitization callbacks, |
||
| 118 | * where keys match keys in your attributes array, |
||
| 119 | * and values represent the sanitization function you wish to be applied to that attribute. |
||
| 120 | * So for example, if you had an integer attribute named "event_id" |
||
| 121 | * that you wanted to be sanitized using absint(), |
||
| 122 | * then you would return the following: |
||
| 123 | * array('event_id' => 'absint') |
||
| 124 | * Entering 'skip_sanitization' for the callback value |
||
| 125 | * means that no sanitization will be applied |
||
| 126 | * on the assumption that the attribute |
||
| 127 | * will be sanitized at some point... right? |
||
| 128 | * You wouldn't pass around unsanitized attributes would you? |
||
| 129 | * That would be very Tom Foolery of you!!! |
||
| 130 | * |
||
| 131 | * @return array |
||
| 132 | */ |
||
| 133 | protected function customAttributeSanitizationMap() |
||
| 137 | |||
| 138 | |||
| 139 | |||
| 140 | /** |
||
| 141 | * Performs basic sanitization on shortcode attributes |
||
| 142 | * Since incoming attributes from the shortcode usage in the WP editor will all be strings, |
||
| 143 | * most attributes will by default be sanitized using the sanitize_text_field() function. |
||
| 144 | * This can be overridden using the customAttributeSanitizationMap() method (see above), |
||
| 145 | * all other attributes would be sanitized using the defaults in the switch statement below |
||
| 146 | * |
||
| 147 | * @param array $attributes |
||
| 148 | * @return array |
||
| 149 | */ |
||
| 150 | private function sanitizeAttributes(array $attributes) |
||
| 188 | |||
| 189 | |||
| 190 | |||
| 191 | } |
||
| 192 | // End of file EspressoShortcode.php |
||
| 193 | // Location: EventEspresso\core\services\shortcodes/EspressoShortcode.php |
This check looks for calls to methods that do not seem to exist on a given type. It looks for the method on the type itself as well as in inherited classes or implemented interfaces.
This is most likely a typographical error or the method has been renamed.