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 |
||
| 15 | class Editor |
||
| 16 | { |
||
| 17 | /** |
||
| 18 | * Name of the instance. |
||
| 19 | * |
||
| 20 | * @access protected |
||
| 21 | * @var string |
||
| 22 | */ |
||
| 23 | public $name; |
||
| 24 | |||
| 25 | /** |
||
| 26 | * Name of the toolbar to load. |
||
| 27 | * |
||
| 28 | * @var string |
||
| 29 | */ |
||
| 30 | public $toolbarSet; |
||
| 31 | |||
| 32 | /** |
||
| 33 | * Initial value. |
||
| 34 | * |
||
| 35 | * @var string |
||
| 36 | */ |
||
| 37 | public $value; |
||
| 38 | |||
| 39 | /** |
||
| 40 | * @var array |
||
| 41 | */ |
||
| 42 | public $config; |
||
| 43 | |||
| 44 | /** @var TranslatorInterface */ |
||
| 45 | public $translator; |
||
| 46 | |||
| 47 | /** @var RouterInterface */ |
||
| 48 | public $urlGenerator; |
||
| 49 | |||
| 50 | /** @var \Template */ |
||
| 51 | public $template; |
||
| 52 | |||
| 53 | /** |
||
| 54 | * Editor constructor. |
||
| 55 | * @param TranslatorInterface $translator |
||
| 56 | * @param RouterInterface $urlGenerator |
||
| 57 | */ |
||
| 58 | public function __construct( |
||
| 73 | |||
| 74 | /** |
||
| 75 | * @return string |
||
| 76 | */ |
||
| 77 | public function getName() |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @param string $name |
||
| 84 | */ |
||
| 85 | public function setName($name) |
||
| 89 | |||
| 90 | /** |
||
| 91 | * Return the HTML code required to run editor. |
||
| 92 | * |
||
| 93 | * @return string |
||
| 94 | */ |
||
| 95 | public function createHtml() |
||
| 101 | |||
| 102 | /** |
||
| 103 | * @return string |
||
| 104 | */ |
||
| 105 | View Code Duplication | public function editorReplace() |
|
| 126 | |||
| 127 | /** |
||
| 128 | * Converts a PHP variable into its Javascript equivalent. |
||
| 129 | * The code of this method has been "borrowed" from the function drupal_to_js() within the Drupal CMS. |
||
| 130 | * @param mixed $var The variable to be converted into Javascript syntax |
||
| 131 | * |
||
| 132 | * @return string Returns a string |
||
| 133 | * Note: This function is similar to json_encode(), |
||
| 134 | * in addition it produces HTML-safe strings, i.e. with <, > and & escaped. |
||
| 135 | * @link http://drupal.org/ |
||
| 136 | */ |
||
| 137 | protected function toJavascript($var) |
||
| 181 | |||
| 182 | /** |
||
| 183 | * @param string $key |
||
| 184 | * @param mixed $value |
||
| 185 | */ |
||
| 186 | public function setConfigAttribute($key, $value) |
||
| 190 | |||
| 191 | /** |
||
| 192 | * @param string $key |
||
| 193 | * |
||
| 194 | * @return mixed |
||
| 195 | */ |
||
| 196 | public function getConfigAttribute($key) |
||
| 200 | |||
| 201 | /** |
||
| 202 | * @param array $config |
||
| 203 | */ |
||
| 204 | public function processConfig($config) |
||
| 234 | |||
| 235 | /** |
||
| 236 | * @return null |
||
| 237 | */ |
||
| 238 | public function getEditorTemplate() |
||
| 242 | |||
| 243 | /** |
||
| 244 | * @return string |
||
| 245 | */ |
||
| 246 | public function getEditorStandAloneTemplate() |
||
| 250 | |||
| 251 | /** |
||
| 252 | * @return null |
||
| 253 | */ |
||
| 254 | public function formatTemplates($templates) |
||
| 258 | |||
| 259 | /** |
||
| 260 | * @return string |
||
| 261 | */ |
||
| 262 | public function getLocale() |
||
| 266 | } |
||
| 267 |