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 |
||
| 26 | class DhtmlTextArea extends \XoopsEditor |
||
| 27 | { |
||
| 28 | /** |
||
| 29 | * Extended HTML editor |
||
| 30 | * |
||
| 31 | * <p>If an extended HTML editor is set, the renderer will be replaced by the specified editor, |
||
| 32 | * usually a visual or WYSIWYG editor.</p> |
||
| 33 | * |
||
| 34 | * <ul>Developer and user guide: |
||
| 35 | * <li> |
||
| 36 | * <ul>For run-time settings per call |
||
| 37 | * <li>To use an editor pre-configured by {@link XoopsEditor}, e.g. 'fckeditor': <code>$options['editor'] = 'fckeditor';</code></li> |
||
| 38 | * <li>To use a custom editor, e.g. 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>$options['editor'] = array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> |
||
| 39 | * </ul> |
||
| 40 | * </li> |
||
| 41 | * <li> |
||
| 42 | * <ul>For pre-configured settings, which will force to use a editor if no specific editor is set for call |
||
| 43 | * <li> |
||
| 44 | * <ul>Set up custom configs: in XOOPS_VAR_PATH . '/configs/xoopsconfig.php' set a editor as default, e.g. |
||
| 45 | * <li>a pre-configured editor 'fckeditor': <code>return array('editor' => 'fckeditor');</code></li> |
||
| 46 | * <li>a custom editor 'MyEditor' class located in "/modules/myeditor/myeditor.php": <code>return array('editor' => array('MyEditor', XOOPS_ROOT_PATH . "/modules/myeditor/myeditor.php");</code></li> |
||
| 47 | * </ul> |
||
| 48 | * </li> |
||
| 49 | * <li>To disable the default editor, in XOOPS_VAR_PATH . '/configs/xoopsconfig.php': <code>return array();</code></li> |
||
| 50 | * <li>To disable the default editor for a specific call: <code>$options['editor'] = 'dhtmltextarea';</code></li> |
||
| 51 | * </ul> |
||
| 52 | * </li> |
||
| 53 | * </ul> |
||
| 54 | */ |
||
| 55 | /** |
||
| 56 | * @var \XoopsEditor |
||
| 57 | */ |
||
| 58 | public $htmlEditor; |
||
| 59 | |||
| 60 | /** |
||
| 61 | * Hidden text |
||
| 62 | * |
||
| 63 | * @var string |
||
| 64 | */ |
||
| 65 | private $hiddenText; |
||
| 66 | |||
| 67 | /** |
||
| 68 | * @var bool |
||
| 69 | */ |
||
| 70 | public $skipPreview = false; |
||
| 71 | |||
| 72 | /** |
||
| 73 | * @var bool |
||
| 74 | */ |
||
| 75 | public $doHtml = false; |
||
| 76 | |||
| 77 | /** |
||
| 78 | * @var string |
||
| 79 | */ |
||
| 80 | public $js = ''; |
||
| 81 | |||
| 82 | /** |
||
| 83 | * @var array |
||
| 84 | */ |
||
| 85 | public $configs = array(); |
||
| 86 | |||
| 87 | /** |
||
| 88 | * Constructor |
||
| 89 | * |
||
| 90 | * @param string $caption Caption |
||
| 91 | * @param string $name name attribute |
||
| 92 | * @param string $value Initial text |
||
| 93 | * @param integer $rows Number of rows |
||
| 94 | * @param integer $cols Number of columns |
||
| 95 | * @param string $hiddentext Identifier for hidden Text |
||
| 96 | * @param array $options Extra options |
||
| 97 | */ |
||
| 98 | 2 | public function __construct( |
|
| 157 | |||
| 158 | /** |
||
| 159 | * Prepare HTML for output |
||
| 160 | * |
||
| 161 | * @return string HTML |
||
| 162 | */ |
||
| 163 | 1 | public function render() |
|
| 164 | { |
||
| 165 | 1 | View Code Duplication | if ($this->htmlEditor && is_object($this->htmlEditor)) { |
| 166 | if (!isset($this->htmlEditor->isEnabled) || $this->htmlEditor->isEnabled) { |
||
| 167 | return $this->htmlEditor->render(); |
||
| 168 | } |
||
| 169 | } |
||
| 170 | 1 | static $js_loaded; |
|
| 171 | |||
| 172 | 1 | $xoops = \Xoops::getInstance(); |
|
| 173 | |||
| 174 | 1 | $extra = ($this->getExtra() != '' ? " " . $this->getExtra() : ''); |
|
| 175 | 1 | $ret = ""; |
|
| 176 | // actions |
||
| 177 | 1 | $ret .= $this->codeIcon() . "<br />\n"; |
|
| 178 | // fonts |
||
| 179 | 1 | $ret .= $this->fontArray(); |
|
| 180 | // length checker |
||
| 181 | $ret .= '<button type="button" class="btn btn-xs btn-default" onclick="XoopsCheckLength(\'' |
||
| 182 | 1 | . $this->getName() . '\', \'' . @$this->configs['maxlength'] . '\', \'' |
|
| 183 | 1 | . \XoopsLocale::F_CURRENT_TEXT_LENGTH . '\', \'' . \XoopsLocale::MAXIMUM_LENGTH . '\');"' |
|
| 184 | 1 | . ' title="' . \XoopsLocale::CHECK_TEXT_LENGTH . '">' |
|
| 185 | 1 | . '<span class="glyphicon glyphicon-check"></span></button>'; |
|
| 186 | 1 | $ret .= "\n"; |
|
| 187 | // the textarea box |
||
| 188 | |||
| 189 | 1 | $this->suppressRender(['value']); |
|
| 190 | 1 | $this->themeDecorateElement(); |
|
| 191 | 1 | $attributes = $this->renderAttributeString(); |
|
| 192 | |||
| 193 | 1 | $ret .= '<textarea ' . $attributes . $extra . '>' . $this->getValue() . "</textarea>\n"; |
|
| 194 | |||
| 195 | 1 | if (empty($this->skipPreview)) { |
|
| 196 | 1 | if (!$xoops->theme()) { |
|
| 197 | $this->js .= implode("", file($xoops->path('media/xoops/image.js'))); |
||
| 198 | } else { |
||
| 199 | 1 | $xoops->theme()->addScript('media/xoops/image.js', array('type' => 'text/javascript')); |
|
| 200 | } |
||
| 201 | 1 | $button = "<input id='" . $this->getName() . "_preview_button' " . "type='button' " . "class='btn btn-sm btn-default' value='" . \XoopsLocale::A_PREVIEW . "' " . "onclick=\"form_instantPreview('" . XOOPS_URL . "', '" . $this->getName() . "','" . XOOPS_URL . "/images', " . (int)($this->doHtml) . ", '" . $xoops->security()->createToken() . "')\"" . " />"; |
|
| 202 | 1 | $ret .= "<br />" . "<div id='" . $this->getName() . "_hidden' style='display: block;'> " . "<fieldset>" . "<legend>" . $button . "</legend>" . "<div id='" . $this->getName() . "_hidden_data'>" . \XoopsLocale::CLICK_PREVIEW_TO_SEE_CONTENT . "</div>" . "</fieldset>" . "</div>"; |
|
| 203 | } |
||
| 204 | // Load javascript |
||
| 205 | 1 | if (empty($js_loaded)) { |
|
| 206 | 1 | $javascript = (($this->js) |
|
| 207 | 1 | ? '<script type="text/javascript">' . $this->js . '</script>' |
|
| 208 | 1 | : '') . '<script type="text/javascript" src="' . \XoopsBaseConfig::get('url') . '/include/formdhtmltextarea.js"></script>'; |
|
| 209 | 1 | $ret = $javascript . $ret; |
|
| 210 | 1 | $js_loaded = true; |
|
| 211 | } |
||
| 212 | 1 | return $ret; |
|
| 213 | } |
||
| 214 | |||
| 215 | /** |
||
| 216 | * codeIcon |
||
| 217 | * |
||
| 218 | * @return string |
||
| 219 | */ |
||
| 220 | 1 | public function codeIcon() |
|
| 221 | { |
||
| 222 | 1 | $textarea_id = $this->getName(); |
|
| 223 | 1 | $xoops = \Xoops::getInstance(); |
|
| 224 | 1 | $myts = \Xoops\Core\Text\Sanitizer::getInstance(); |
|
| 225 | |||
| 226 | 1 | $code = ''; |
|
| 227 | 1 | $code .= '<img src="' . $xoops->url('images/form/url.gif') . '" alt="' . \XoopsLocale::URL |
|
| 228 | 1 | . '" title="' . \XoopsLocale::URL . '" onclick="xoopsCodeUrl(\'' . $textarea_id . '\', \'' |
|
| 229 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_LINK_URL) . '\', \'' |
|
| 230 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_WEBSITE_TITLE) |
|
| 231 | 1 | . '\')" onmouseover="style.cursor=\'hand\'" /> '; |
|
| 232 | 1 | $code .= '<img src="' . $xoops->url('images/form/email.gif') . '" alt="' . \XoopsLocale::EMAIL |
|
| 233 | 1 | . '" title="' . \XoopsLocale::EMAIL . '" onclick="xoopsCodeEmail(\'' . $textarea_id . '\', \'' |
|
| 234 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_EMAIL) |
|
| 235 | 1 | . '\');" onmouseover="style.cursor=\'hand\'" /> '; |
|
| 236 | 1 | $code .= '<img src="' . $xoops->url('images/form/imgsrc.gif') . '" alt="' . \XoopsLocale::IMAGES |
|
| 237 | 1 | . '" title="' . \XoopsLocale::IMAGES . '" onclick="xoopsCodeImg(\'' . $textarea_id . '\', \'' |
|
| 238 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_IMAGE_URL) . '\', \'' |
|
| 239 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_IMAGE_POSITION) . '\', \'' |
|
| 240 | 1 | . $myts->escapeForJavascript(\XoopsLocale::IMAGE_POSITION_DESCRIPTION) . '\', \'' |
|
| 241 | 1 | . $myts->escapeForJavascript(\XoopsLocale::E_ENTER_IMAGE_POSITION) . '\', \'' |
|
| 242 | 1 | . $myts->escapeForJavascript(\XoopsLocale::WIDTH) . '\');" onmouseover="style.cursor=\'hand\'" /> '; |
|
| 243 | |||
| 244 | 1 | $extensions = array_filter($myts->listExtensions()); |
|
| 245 | 1 | foreach ($extensions as $extension) { |
|
| 246 | 1 | list ($button, $js) = $myts->getDhtmlEditorSupport($extension, $textarea_id); |
|
| 247 | 1 | if (!empty($button)) { |
|
| 248 | 1 | $code .= $button; |
|
| 249 | } |
||
| 250 | 1 | if (!empty($js)) { |
|
| 251 | 1 | $this->js .= $js; |
|
| 252 | } |
||
| 253 | } |
||
| 254 | 1 | $code .= '<img src="' . $xoops->url('images/form/code.gif') .'" alt="' . \XoopsLocale::SOURCE_CODE . '" title="' |
|
| 255 | 1 | . \XoopsLocale::SOURCE_CODE . '" onclick="xoopsCodeCode(\'' . $textarea_id . '\', \'' |
|
| 256 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_CODE) . '\');" onmouseover="style.cursor=\'hand\'" /> '; |
|
| 257 | |||
| 258 | 1 | $code .= '<img src="' . $xoops->url('images/form/quote.gif') .'" alt="' . \XoopsLocale::QUOTE . '" title="' |
|
| 259 | 1 | . \XoopsLocale::QUOTE . '" onclick="xoopsCodeQuote(\'' . $textarea_id . '\', \'' |
|
| 260 | 1 | . $myts->escapeForJavascript(\XoopsLocale::ENTER_QUOTE) . '\');" onmouseover="style.cursor=\'hand\'" /> '; |
|
| 261 | |||
| 262 | 1 | $response = \Xoops::getInstance()->service('emoji')->renderEmojiSelector($this->getName()); |
|
| 263 | 1 | if ($response->isSuccess()) { |
|
| 264 | $emojiSelector = $response->getValue(); |
||
| 265 | $code .= $emojiSelector; |
||
| 266 | } |
||
| 267 | |||
| 268 | 1 | return $code; |
|
| 269 | } |
||
| 270 | |||
| 271 | /** |
||
| 272 | * fontArray |
||
| 273 | * |
||
| 274 | * @return string |
||
| 275 | */ |
||
| 276 | 1 | public function fontArray() |
|
| 324 | |||
| 325 | /** |
||
| 326 | * renderValidationJS |
||
| 327 | * |
||
| 328 | * @return bool|string |
||
| 329 | */ |
||
| 330 | 1 | public function renderValidationJS() |
|
| 339 | } |
||
| 340 |
Our type inference engine has found an assignment to a property that is incompatible with the declared type of that property.
Either this assignment is in error or the assigned type should be added to the documentation/type hint for that property..