| Conditions | 43 |
| Paths | 2160 |
| Total Lines | 162 |
| Code Lines | 98 |
| Lines | 27 |
| Ratio | 16.67 % |
| Changes | 0 | ||
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | <?php |
||
| 220 | protected function setupConfigStuff($config) { |
||
| 221 | |||
| 222 | $block_wrapper = $config->get('HTML.BlockWrapper'); |
||
| 223 | if (isset($this->info_content_sets['Block'][$block_wrapper])) { |
||
| 224 | $this->info_block_wrapper = $block_wrapper; |
||
| 225 | } else { |
||
| 226 | trigger_error('Cannot use non-block element as block wrapper', |
||
| 227 | E_USER_ERROR); |
||
| 228 | } |
||
| 229 | |||
| 230 | $parent = $config->get('HTML.Parent'); |
||
| 231 | $def = $this->manager->getElement($parent, true); |
||
| 232 | if ($def) { |
||
| 233 | $this->info_parent = $parent; |
||
| 234 | $this->info_parent_def = $def; |
||
| 235 | } else { |
||
| 236 | trigger_error('Cannot use unrecognized element as parent', |
||
| 237 | E_USER_ERROR); |
||
| 238 | $this->info_parent_def = $this->manager->getElement($this->info_parent, true); |
||
| 239 | } |
||
| 240 | |||
| 241 | // support template text |
||
| 242 | $support = "(for information on implementing this, see the ". |
||
| 243 | "support forums) "; |
||
| 244 | |||
| 245 | // setup allowed elements ----------------------------------------- |
||
| 246 | |||
| 247 | $allowed_elements = $config->get('HTML.AllowedElements'); |
||
| 248 | $allowed_attributes = $config->get('HTML.AllowedAttributes'); // retrieve early |
||
| 249 | |||
| 250 | if (!is_array($allowed_elements) && !is_array($allowed_attributes)) { |
||
| 251 | $allowed = $config->get('HTML.Allowed'); |
||
| 252 | if (is_string($allowed)) { |
||
| 253 | list($allowed_elements, $allowed_attributes) = $this->parseTinyMCEAllowedList($allowed); |
||
| 254 | } |
||
| 255 | } |
||
| 256 | |||
| 257 | View Code Duplication | if (is_array($allowed_elements)) { |
|
| 258 | foreach ($this->info as $name => $d) { |
||
| 259 | if(!isset($allowed_elements[$name])) unset($this->info[$name]); |
||
| 260 | unset($allowed_elements[$name]); |
||
| 261 | } |
||
| 262 | // emit errors |
||
| 263 | foreach ($allowed_elements as $element => $d) { |
||
| 264 | $element = htmlspecialchars($element, ENT_COMPAT | ENT_HTML401, 'UTF-8', false); // PHP doesn't escape errors, be careful! |
||
| 265 | trigger_error("Element '$element' is not supported $support", E_USER_WARNING); |
||
| 266 | } |
||
| 267 | } |
||
| 268 | |||
| 269 | // setup allowed attributes --------------------------------------- |
||
| 270 | |||
| 271 | $allowed_attributes_mutable = $allowed_attributes; // by copy! |
||
| 272 | if (is_array($allowed_attributes)) { |
||
| 273 | |||
| 274 | // This actually doesn't do anything, since we went away from |
||
| 275 | // global attributes. It's possible that userland code uses |
||
| 276 | // it, but HTMLModuleManager doesn't! |
||
| 277 | foreach ($this->info_global_attr as $attr => $x) { |
||
| 278 | $keys = array($attr, "*@$attr", "*.$attr"); |
||
| 279 | $delete = true; |
||
| 280 | View Code Duplication | foreach ($keys as $key) { |
|
| 281 | if ($delete && isset($allowed_attributes[$key])) { |
||
| 282 | $delete = false; |
||
| 283 | } |
||
| 284 | if (isset($allowed_attributes_mutable[$key])) { |
||
| 285 | unset($allowed_attributes_mutable[$key]); |
||
| 286 | } |
||
| 287 | } |
||
| 288 | if ($delete) unset($this->info_global_attr[$attr]); |
||
| 289 | } |
||
| 290 | |||
| 291 | foreach ($this->info as $tag => $info) { |
||
| 292 | foreach ($info->attr as $attr => $x) { |
||
| 293 | $keys = array("$tag@$attr", $attr, "*@$attr", "$tag.$attr", "*.$attr"); |
||
| 294 | $delete = true; |
||
| 295 | View Code Duplication | foreach ($keys as $key) { |
|
| 296 | if ($delete && isset($allowed_attributes[$key])) { |
||
| 297 | $delete = false; |
||
| 298 | } |
||
| 299 | if (isset($allowed_attributes_mutable[$key])) { |
||
| 300 | unset($allowed_attributes_mutable[$key]); |
||
| 301 | } |
||
| 302 | } |
||
| 303 | if ($delete) { |
||
| 304 | if ($this->info[$tag]->attr[$attr]->required) { |
||
| 305 | trigger_error("Required attribute '$attr' in element '$tag' was not allowed, which means '$tag' will not be allowed either", E_USER_WARNING); |
||
| 306 | } |
||
| 307 | unset($this->info[$tag]->attr[$attr]); |
||
| 308 | } |
||
| 309 | } |
||
| 310 | } |
||
| 311 | // emit errors |
||
| 312 | foreach ($allowed_attributes_mutable as $elattr => $d) { |
||
| 313 | $bits = preg_split('/[.@]/', $elattr, 2); |
||
| 314 | $c = count($bits); |
||
| 315 | switch ($c) { |
||
| 316 | case 2: |
||
| 317 | if ($bits[0] !== '*') { |
||
| 318 | $element = htmlspecialchars($bits[0], ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
||
| 319 | $attribute = htmlspecialchars($bits[1], ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
||
| 320 | if (!isset($this->info[$element])) { |
||
| 321 | trigger_error("Cannot allow attribute '$attribute' if element '$element' is not allowed/supported $support"); |
||
| 322 | } else { |
||
| 323 | trigger_error("Attribute '$attribute' in element '$element' not supported $support", |
||
| 324 | E_USER_WARNING); |
||
| 325 | } |
||
| 326 | break; |
||
| 327 | } |
||
| 328 | // otherwise fall through |
||
| 329 | case 1: |
||
| 330 | $attribute = htmlspecialchars($bits[0], ENT_COMPAT | ENT_HTML401, 'UTF-8', false); |
||
| 331 | trigger_error("Global attribute '$attribute' is not ". |
||
| 332 | "supported in any elements $support", |
||
| 333 | E_USER_WARNING); |
||
| 334 | break; |
||
| 335 | } |
||
| 336 | } |
||
| 337 | |||
| 338 | } |
||
| 339 | |||
| 340 | // setup forbidden elements --------------------------------------- |
||
| 341 | |||
| 342 | $forbidden_elements = $config->get('HTML.ForbiddenElements'); |
||
| 343 | $forbidden_attributes = $config->get('HTML.ForbiddenAttributes'); |
||
| 344 | |||
| 345 | foreach ($this->info as $tag => $info) { |
||
| 346 | if (isset($forbidden_elements[$tag])) { |
||
| 347 | unset($this->info[$tag]); |
||
| 348 | continue; |
||
| 349 | } |
||
| 350 | foreach ($info->attr as $attr => $x) { |
||
| 351 | if ( |
||
| 352 | isset($forbidden_attributes["$tag@$attr"]) || |
||
| 353 | isset($forbidden_attributes["*@$attr"]) || |
||
| 354 | isset($forbidden_attributes[$attr]) |
||
| 355 | ) { |
||
| 356 | unset($this->info[$tag]->attr[$attr]); |
||
| 357 | continue; |
||
| 358 | } // this segment might get removed eventually |
||
| 359 | elseif (isset($forbidden_attributes["$tag.$attr"])) { |
||
| 360 | // $tag.$attr are not user supplied, so no worries! |
||
| 361 | trigger_error("Error with $tag.$attr: tag.attr syntax not supported for HTML.ForbiddenAttributes; use tag@attr instead", E_USER_WARNING); |
||
| 362 | } |
||
| 363 | } |
||
| 364 | } |
||
| 365 | foreach ($forbidden_attributes as $key => $v) { |
||
| 366 | if (strlen($key) < 2) continue; |
||
| 367 | if ($key[0] != '*') continue; |
||
| 368 | if ($key[1] == '.') { |
||
| 369 | trigger_error("Error with $key: *.attr syntax not supported for HTML.ForbiddenAttributes; use attr instead", E_USER_WARNING); |
||
| 370 | } |
||
| 371 | } |
||
| 372 | |||
| 373 | // setup injectors ----------------------------------------------------- |
||
| 374 | foreach ($this->info_injector as $i => $injector) { |
||
| 375 | if ($injector->checkNeeded($config) !== false) { |
||
| 376 | // remove injector that does not have it's required |
||
| 377 | // elements/attributes present, and is thus not needed. |
||
| 378 | unset($this->info_injector[$i]); |
||
| 379 | } |
||
| 380 | } |
||
| 381 | } |
||
| 382 | |||
| 426 |
This check marks PHPDoc comments that could not be parsed by our parser. To see which comment annotations we can parse, please refer to our documentation on supported doc-types.