Conditions | 43 |
Paths | 2160 |
Total Lines | 184 |
Code Lines | 113 |
Lines | 0 |
Ratio | 0 % |
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 |
||
261 | protected function setupConfigStuff($config) |
||
262 | { |
||
263 | $block_wrapper = $config->get('HTML.BlockWrapper'); |
||
264 | if (isset($this->info_content_sets['Block'][$block_wrapper])) { |
||
265 | $this->info_block_wrapper = $block_wrapper; |
||
266 | } else { |
||
267 | trigger_error( |
||
268 | 'Cannot use non-block element as block wrapper', |
||
269 | E_USER_ERROR |
||
270 | ); |
||
271 | } |
||
272 | |||
273 | $parent = $config->get('HTML.Parent'); |
||
274 | $def = $this->manager->getElement($parent, true); |
||
275 | if ($def) { |
||
276 | $this->info_parent = $parent; |
||
277 | $this->info_parent_def = $def; |
||
278 | } else { |
||
279 | trigger_error( |
||
280 | 'Cannot use unrecognized element as parent', |
||
281 | E_USER_ERROR |
||
282 | ); |
||
283 | $this->info_parent_def = $this->manager->getElement($this->info_parent, true); |
||
284 | } |
||
285 | |||
286 | // support template text |
||
287 | $support = "(for information on implementing this, see the support forums) "; |
||
288 | |||
289 | // setup allowed elements ----------------------------------------- |
||
290 | |||
291 | $allowed_elements = $config->get('HTML.AllowedElements'); |
||
292 | $allowed_attributes = $config->get('HTML.AllowedAttributes'); // retrieve early |
||
293 | |||
294 | if (!is_array($allowed_elements) && !is_array($allowed_attributes)) { |
||
295 | $allowed = $config->get('HTML.Allowed'); |
||
296 | if (is_string($allowed)) { |
||
297 | list($allowed_elements, $allowed_attributes) = $this->parseTinyMCEAllowedList($allowed); |
||
298 | } |
||
299 | } |
||
300 | |||
301 | if (is_array($allowed_elements)) { |
||
302 | foreach ($this->info as $name => $d) { |
||
303 | if (!isset($allowed_elements[$name])) { |
||
304 | unset($this->info[$name]); |
||
305 | } |
||
306 | unset($allowed_elements[$name]); |
||
307 | } |
||
308 | // emit errors |
||
309 | foreach ($allowed_elements as $element => $d) { |
||
310 | $element = htmlspecialchars($element); // PHP doesn't escape errors, be careful! |
||
311 | trigger_error("Element '$element' is not supported $support", E_USER_WARNING); |
||
312 | } |
||
313 | } |
||
314 | |||
315 | // setup allowed attributes --------------------------------------- |
||
316 | |||
317 | $allowed_attributes_mutable = $allowed_attributes; // by copy! |
||
318 | if (is_array($allowed_attributes)) { |
||
319 | // This actually doesn't do anything, since we went away from |
||
320 | // global attributes. It's possible that userland code uses |
||
321 | // it, but HTMLModuleManager doesn't! |
||
322 | foreach ($this->info_global_attr as $attr => $x) { |
||
323 | $keys = array($attr, "*@$attr", "*.$attr"); |
||
324 | $delete = true; |
||
325 | foreach ($keys as $key) { |
||
326 | if ($delete && isset($allowed_attributes[$key])) { |
||
327 | $delete = false; |
||
328 | } |
||
329 | if (isset($allowed_attributes_mutable[$key])) { |
||
330 | unset($allowed_attributes_mutable[$key]); |
||
331 | } |
||
332 | } |
||
333 | if ($delete) { |
||
334 | unset($this->info_global_attr[$attr]); |
||
335 | } |
||
336 | } |
||
337 | |||
338 | foreach ($this->info as $tag => $info) { |
||
339 | foreach ($info->attr as $attr => $x) { |
||
340 | $keys = array("$tag@$attr", $attr, "*@$attr", "$tag.$attr", "*.$attr"); |
||
341 | $delete = true; |
||
342 | foreach ($keys as $key) { |
||
343 | if ($delete && isset($allowed_attributes[$key])) { |
||
344 | $delete = false; |
||
345 | } |
||
346 | if (isset($allowed_attributes_mutable[$key])) { |
||
347 | unset($allowed_attributes_mutable[$key]); |
||
348 | } |
||
349 | } |
||
350 | if ($delete) { |
||
351 | if ($this->info[$tag]->attr[$attr]->required) { |
||
352 | trigger_error( |
||
353 | "Required attribute '$attr' in element '$tag' " . |
||
354 | "was not allowed, which means '$tag' will not be allowed either", |
||
355 | E_USER_WARNING |
||
356 | ); |
||
357 | } |
||
358 | unset($this->info[$tag]->attr[$attr]); |
||
359 | } |
||
360 | } |
||
361 | } |
||
362 | // emit errors |
||
363 | foreach ($allowed_attributes_mutable as $elattr => $d) { |
||
364 | $bits = preg_split('/[.@]/', $elattr, 2); |
||
365 | $c = count($bits); |
||
366 | switch ($c) { |
||
367 | case 2: |
||
368 | if ($bits[0] !== '*') { |
||
369 | $element = htmlspecialchars($bits[0]); |
||
370 | $attribute = htmlspecialchars($bits[1]); |
||
371 | if (!isset($this->info[$element])) { |
||
372 | trigger_error( |
||
373 | "Cannot allow attribute '$attribute' if element " . |
||
374 | "'$element' is not allowed/supported $support" |
||
375 | ); |
||
376 | } else { |
||
377 | trigger_error( |
||
378 | "Attribute '$attribute' in element '$element' not supported $support", |
||
379 | E_USER_WARNING |
||
380 | ); |
||
381 | } |
||
382 | break; |
||
383 | } |
||
384 | // otherwise fall through |
||
385 | case 1: |
||
386 | $attribute = htmlspecialchars($bits[0]); |
||
387 | trigger_error( |
||
388 | "Global attribute '$attribute' is not ". |
||
389 | "supported in any elements $support", |
||
390 | E_USER_WARNING |
||
391 | ); |
||
392 | break; |
||
393 | } |
||
394 | } |
||
395 | } |
||
396 | |||
397 | // setup forbidden elements --------------------------------------- |
||
398 | |||
399 | $forbidden_elements = $config->get('HTML.ForbiddenElements'); |
||
400 | $forbidden_attributes = $config->get('HTML.ForbiddenAttributes'); |
||
401 | |||
402 | foreach ($this->info as $tag => $info) { |
||
403 | if (isset($forbidden_elements[$tag])) { |
||
404 | unset($this->info[$tag]); |
||
405 | continue; |
||
406 | } |
||
407 | foreach ($info->attr as $attr => $x) { |
||
408 | if (isset($forbidden_attributes["$tag@$attr"]) || |
||
409 | isset($forbidden_attributes["*@$attr"]) || |
||
410 | isset($forbidden_attributes[$attr]) |
||
411 | ) { |
||
412 | unset($this->info[$tag]->attr[$attr]); |
||
413 | continue; |
||
414 | } elseif (isset($forbidden_attributes["$tag.$attr"])) { // this segment might get removed eventually |
||
415 | // $tag.$attr are not user supplied, so no worries! |
||
416 | trigger_error( |
||
417 | "Error with $tag.$attr: tag.attr syntax not supported for " . |
||
418 | "HTML.ForbiddenAttributes; use tag@attr instead", |
||
419 | E_USER_WARNING |
||
420 | ); |
||
421 | } |
||
422 | } |
||
423 | } |
||
424 | foreach ($forbidden_attributes as $key => $v) { |
||
425 | if (strlen($key) < 2) { |
||
426 | continue; |
||
427 | } |
||
428 | if ($key[0] != '*') { |
||
429 | continue; |
||
430 | } |
||
431 | if ($key[1] == '.') { |
||
432 | trigger_error( |
||
433 | "Error with $key: *.attr syntax not supported for HTML.ForbiddenAttributes; use attr instead", |
||
434 | E_USER_WARNING |
||
435 | ); |
||
436 | } |
||
437 | } |
||
438 | |||
439 | // setup injectors ----------------------------------------------------- |
||
440 | foreach ($this->info_injector as $i => $injector) { |
||
441 | if ($injector->checkNeeded($config) !== false) { |
||
442 | // remove injector that does not have it's required |
||
443 | // elements/attributes present, and is thus not needed. |
||
444 | unset($this->info_injector[$i]); |
||
445 | } |
||
494 |
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..