Conditions | 45 |
Paths | > 20000 |
Total Lines | 271 |
Code Lines | 132 |
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 |
||
360 | public function render(array $options = []) |
||
361 | { |
||
362 | if (profiler() !== false) { |
||
363 | profiler()->watch('Starting View Rendering'); |
||
364 | } |
||
365 | |||
366 | parser()->loadVars(presenter()->getArrayCopy()); |
||
367 | |||
368 | if (false !== ($pagePresets = presenter()->page->getPresets())) { |
||
369 | /** |
||
370 | * Sets Page Theme |
||
371 | */ |
||
372 | if ($pagePresets->offsetExists('theme')) { |
||
373 | presenter()->setTheme($pagePresets->theme); |
||
374 | } elseif (false !== ($theme = presenter()->getConfig('theme'))) { |
||
375 | if (modules()->current()->hasTheme($theme)) { |
||
376 | presenter()->setTheme($theme); |
||
377 | } |
||
378 | } |
||
379 | |||
380 | /** |
||
381 | * Sets Page Layout |
||
382 | */ |
||
383 | if (presenter()->theme !== false) { |
||
384 | if ($pagePresets->offsetExists('layout')) { |
||
385 | presenter()->theme->setLayout($pagePresets->layout); |
||
386 | } |
||
387 | |||
388 | if (false !== ($modulePresets = modules()->current()->getPresets())) { |
||
389 | |||
390 | /** |
||
391 | * Autoload Module Assets |
||
392 | */ |
||
393 | if ($modulePresets->offsetExists('assets')) { |
||
394 | presenter()->assets->autoload($modulePresets->assets); |
||
395 | } |
||
396 | |||
397 | $moduleAssets = [ |
||
398 | 'main', |
||
399 | modules()->current()->getParameter() |
||
400 | ]; |
||
401 | |||
402 | // Autoload Assets |
||
403 | presenter()->assets->loadCss($moduleAssets); |
||
404 | presenter()->assets->loadJs($moduleAssets); |
||
405 | |||
406 | /** |
||
407 | * Sets Module Meta |
||
408 | */ |
||
409 | if ($modulePresets->offsetExists('title')) { |
||
410 | presenter()->meta->title->append(language()->getLine($modulePresets->title)); |
||
411 | } |
||
412 | |||
413 | if ($modulePresets->offsetExists('pageTitle')) { |
||
414 | presenter()->meta->title->replace(language()->getLine($modulePresets->pageTitle)); |
||
415 | } |
||
416 | |||
417 | if ($modulePresets->offsetExists('browserTitle')) { |
||
418 | presenter()->meta->title->replace(language()->getLine($modulePresets->browserTitle)); |
||
419 | } |
||
420 | |||
421 | if ($modulePresets->offsetExists('meta')) { |
||
422 | foreach ($modulePresets->meta as $name => $content) { |
||
423 | presenter()->meta->store($name, $content); |
||
424 | } |
||
425 | } |
||
426 | } |
||
427 | |||
428 | /** |
||
429 | * Autoload Page Assets |
||
430 | */ |
||
431 | if ($pagePresets->offsetExists('assets')) { |
||
432 | presenter()->assets->autoload($pagePresets->assets); |
||
433 | } |
||
434 | |||
435 | if (presenter()->page->file instanceof \SplFileInfo) { |
||
436 | $pageAssets[] = presenter()->page->file->getDirectoryInfo()->getDirName(); |
||
437 | $pageAssets[] = implode('/', [ |
||
438 | presenter()->page->file->getDirectoryInfo()->getDirName(), |
||
439 | $pageAssets[] = presenter()->page->file->getFilename(), |
||
440 | ]); |
||
441 | |||
442 | // Autoload Assets |
||
443 | presenter()->assets->loadCss($pageAssets); |
||
444 | presenter()->assets->loadJs($pageAssets); |
||
445 | } |
||
446 | |||
447 | /** |
||
448 | * Sets Page Meta |
||
449 | */ |
||
450 | if ($pagePresets->offsetExists('title')) { |
||
451 | presenter()->meta->title->append(language()->getLine($pagePresets->title)); |
||
452 | } |
||
453 | |||
454 | if ($pagePresets->offsetExists('pageTitle')) { |
||
455 | presenter()->meta->title->replace(language()->getLine($pagePresets->pageTitle)); |
||
456 | } |
||
457 | |||
458 | if ($pagePresets->offsetExists('browserTitle')) { |
||
459 | presenter()->meta->title->replace(language()->getLine($pagePresets->browserTitle)); |
||
460 | } |
||
461 | |||
462 | if ($pagePresets->offsetExists('meta')) { |
||
463 | foreach ($pagePresets->meta as $name => $content) { |
||
464 | presenter()->meta->store($name, $content); |
||
465 | } |
||
466 | } |
||
467 | |||
468 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
469 | parser()->loadFile($layout->getRealPath()); |
||
470 | |||
471 | $htmlOutput = parser()->parse(); |
||
472 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
473 | |||
474 | $this->document->loadHTML($htmlOutput); |
||
475 | } |
||
476 | } else { |
||
477 | output()->sendError(204, language()->getLine('E_THEME_NOT_FOUND', [$theme])); |
||
478 | } |
||
479 | } elseif (presenter()->theme instanceof Theme) { |
||
480 | /** |
||
481 | * Autoload Controller Assets |
||
482 | */ |
||
483 | $controllerAssets[] = controller()->getParameter(); |
||
484 | $controllerAssets[] = implode('/', [ |
||
485 | controller()->getParameter(), |
||
486 | controller()->getRequestMethod(), |
||
487 | ]); |
||
488 | |||
489 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
490 | parser()->loadFile($layout->getRealPath()); |
||
491 | |||
492 | $htmlOutput = parser()->parse(); |
||
493 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
494 | |||
495 | $this->document->loadHTML($htmlOutput); |
||
496 | } |
||
497 | } elseif (false !== ($theme = presenter()->getConfig('theme'))) { |
||
498 | if (modules()->current()->hasTheme($theme)) { |
||
499 | presenter()->setTheme($theme); |
||
500 | |||
501 | /** |
||
502 | * Autoload Controller Assets |
||
503 | */ |
||
504 | $controllerAssets[] = controller()->getParameter(); |
||
505 | $controllerAssets[] = implode('/', [ |
||
506 | controller()->getParameter(), |
||
507 | controller()->getRequestMethod(), |
||
508 | ]); |
||
509 | |||
510 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
511 | parser()->loadFile($layout->getRealPath()); |
||
512 | |||
513 | $htmlOutput = parser()->parse(); |
||
514 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
515 | |||
516 | $this->document->loadHTML($htmlOutput); |
||
517 | } |
||
518 | } else { |
||
519 | output()->sendError(204, language()->getLine('E_THEME_NOT_FOUND', [$theme])); |
||
520 | } |
||
521 | } else { |
||
522 | $this->document->find('body')->append(presenter()->partials->__get('content')); |
||
523 | } |
||
524 | |||
525 | /** |
||
526 | * Set Document Meta Title |
||
527 | */ |
||
528 | if (presenter()->meta->title instanceof Meta\Title) { |
||
529 | $this->document->title->text(presenter()->meta->title->__toString()); |
||
530 | } |
||
531 | |||
532 | /** |
||
533 | * Injecting Meta Opengraph |
||
534 | */ |
||
535 | if (presenter()->meta->opengraph instanceof Meta\Opengraph) { |
||
536 | // set opengraph title |
||
537 | if (presenter()->meta->title instanceof Meta\Title) { |
||
538 | presenter()->meta->opengraph->setTitle(presenter()->meta->title->__toString()); |
||
539 | } |
||
540 | |||
541 | // set opengraph site name |
||
542 | if (presenter()->exists('siteName')) { |
||
543 | presenter()->meta->opengraph->setSiteName(presenter()->offsetGet('siteName')); |
||
544 | } |
||
545 | |||
546 | if (presenter()->meta->opengraph->count()) { |
||
547 | $htmlElement = $this->document->getElementsByTagName('html')->item(0); |
||
548 | $htmlElement->setAttribute('prefix', 'og: ' . presenter()->meta->opengraph->prefix); |
||
549 | |||
550 | if (presenter()->meta->opengraph->exists('og:type') === false) { |
||
551 | presenter()->meta->opengraph->setType('website'); |
||
552 | } |
||
553 | |||
554 | $opengraph = presenter()->meta->opengraph->getArrayCopy(); |
||
555 | |||
556 | foreach ($opengraph as $tag) { |
||
557 | $this->document->metaNodes->createElement($tag->attributes->getArrayCopy()); |
||
558 | } |
||
559 | } |
||
560 | } |
||
561 | |||
562 | if (presenter()->meta->count()) { |
||
563 | $meta = presenter()->meta->getArrayCopy(); |
||
564 | |||
565 | foreach ($meta as $tag) { |
||
566 | $this->document->metaNodes->createElement($tag->attributes->getArrayCopy()); |
||
567 | } |
||
568 | } |
||
569 | |||
570 | /** |
||
571 | * Injecting Single Sign-On (SSO) iFrame |
||
572 | */ |
||
573 | if (services()->has('user')) { |
||
574 | $iframe = services()->get('user')->getIframeCode(); |
||
575 | |||
576 | if ( ! empty($iframe)) { |
||
577 | $this->document->find('body')->append($iframe); |
||
578 | } |
||
579 | } |
||
580 | |||
581 | if (input()->env('DEBUG_STAGE') === 'DEVELOPER' and |
||
582 | config()->getItem('presenter')->debugToolBar === true and |
||
583 | services()->has('profiler') |
||
584 | ) { |
||
585 | $this->document->find('body')->append((new Toolbar())->__toString()); |
||
586 | } |
||
587 | |||
588 | /** |
||
589 | * Injecting Progressive Web Application (PWA) Manifest |
||
590 | */ |
||
591 | $this->document->linkNodes->createElement([ |
||
592 | 'rel' => 'manifest', |
||
593 | 'href' => '/manifest.json', |
||
594 | ]); |
||
595 | |||
596 | $htmlOutput = $this->document->saveHTML(); |
||
597 | |||
598 | // Uglify Output |
||
599 | if ($this->config->output[ 'uglify' ] === true) { |
||
600 | $htmlOutput = preg_replace( |
||
601 | [ |
||
602 | '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
||
603 | '/[^\S ]+\</s', // strip whitespaces before tags, except space |
||
604 | '/(\s)+/s', // shorten multiple whitespace sequences |
||
605 | '/<!--(.|\s)*?-->/', // Remove HTML comments |
||
606 | '/<!--(.*)-->/Uis', |
||
607 | "/[[:blank:]]+/", |
||
608 | ], |
||
609 | [ |
||
610 | '>', |
||
611 | '<', |
||
612 | '\\1', |
||
613 | '', |
||
614 | '', |
||
615 | ' ', |
||
616 | ], |
||
617 | str_replace(["\n", "\r", "\t"], '', $htmlOutput)); |
||
618 | } |
||
619 | |||
620 | // Beautify Output |
||
621 | if ($this->config->output[ 'beautify' ] === true) { |
||
622 | $beautifier = new Html\Dom\Beautifier(); |
||
623 | $htmlOutput = $beautifier->format($htmlOutput); |
||
624 | } |
||
625 | |||
626 | if (profiler() !== false) { |
||
627 | profiler()->watch('Ending View Rendering'); |
||
628 | } |
||
629 | |||
630 | return $htmlOutput; |
||
631 | } |
||
633 |
Our type inference engine has found a suspicous assignment of a value to a property. This check raises an issue when a value that can be of a mixed type is assigned to a property that is type hinted more strictly.
For example, imagine you have a variable
$accountId
that can either hold an Id object or false (if there is no account id yet). Your code now assigns that value to theid
property of an instance of theAccount
class. This class holds a proper account, so the id value must no longer be false.Either this assignment is in error or a type check should be added for that assignment.