| Conditions | 62 |
| Paths | > 20000 |
| Total Lines | 415 |
| Code Lines | 200 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 7 | ||
| Bugs | 4 | Features | 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 |
||
| 358 | public function render(array $options = []) |
||
| 359 | { |
||
| 360 | if (profiler() !== false) { |
||
| 361 | profiler()->watch('Starting View Rendering'); |
||
| 362 | } |
||
| 363 | |||
| 364 | parser()->loadVars(presenter()->getArrayCopy()); |
||
| 365 | |||
| 366 | if (presenter()->page->file instanceof \SplFileInfo) { |
||
| 367 | |||
| 368 | if (false === ($pagePresets = presenter()->page->getPresets())) { |
||
| 369 | if (presenter()->page->file->getFilename() === 'index') { |
||
| 370 | $title = presenter()->page->file->getDirectoryInfo()->getDirName(); |
||
| 371 | } else { |
||
| 372 | $titles[] = presenter()->page->file->getDirectoryInfo()->getDirName(); |
||
| 373 | $titles[] = presenter()->page->file->getFilename(); |
||
| 374 | |||
| 375 | $title = implode(' - ', array_unique($titles)); |
||
| 376 | } |
||
| 377 | |||
| 378 | $pagePresets = new SplArrayObject([ |
||
| 379 | 'title' => readable($title, true), |
||
| 380 | 'access' => 'public', |
||
| 381 | ]); |
||
| 382 | } |
||
| 383 | |||
| 384 | /** |
||
| 385 | * Sets Page Theme |
||
| 386 | */ |
||
| 387 | if ($pagePresets->offsetExists('theme')) { |
||
| 388 | presenter()->setTheme($pagePresets->theme); |
||
| 389 | } elseif (false !== ($theme = presenter()->getConfig('theme'))) { |
||
| 390 | if (modules()->top()->hasTheme($theme)) { |
||
| 391 | presenter()->setTheme($theme); |
||
| 392 | } |
||
| 393 | } |
||
| 394 | |||
| 395 | /** |
||
| 396 | * Sets Page Layout |
||
| 397 | */ |
||
| 398 | if (presenter()->theme !== false) { |
||
| 399 | if ($pagePresets->offsetExists('layout')) { |
||
| 400 | presenter()->theme->setLayout($pagePresets->layout); |
||
| 401 | } |
||
| 402 | |||
| 403 | /** |
||
| 404 | * Autoload Theme Assets |
||
| 405 | */ |
||
| 406 | presenter()->theme->load(); |
||
| 407 | |||
| 408 | if (false !== ($modulePresets = modules()->top()->getPresets())) { |
||
| 409 | |||
| 410 | /** |
||
| 411 | * Autoload Module Assets |
||
| 412 | */ |
||
| 413 | if ($modulePresets->offsetExists('assets')) { |
||
| 414 | presenter()->assets->autoload($modulePresets->assets); |
||
| 415 | } |
||
| 416 | |||
| 417 | /** |
||
| 418 | * Sets Module Meta |
||
| 419 | */ |
||
| 420 | if ($modulePresets->offsetExists('title')) { |
||
| 421 | presenter()->meta->title->append(language()->getLine($modulePresets->title)); |
||
| 422 | } |
||
| 423 | |||
| 424 | if ($modulePresets->offsetExists('pageTitle')) { |
||
| 425 | presenter()->meta->title->replace(language()->getLine($modulePresets->pageTitle)); |
||
| 426 | } |
||
| 427 | |||
| 428 | if ($modulePresets->offsetExists('browserTitle')) { |
||
| 429 | presenter()->meta->title->replace(language()->getLine($modulePresets->browserTitle)); |
||
| 430 | } |
||
| 431 | |||
| 432 | if ($modulePresets->offsetExists('meta')) { |
||
| 433 | foreach ($modulePresets->meta as $name => $content) { |
||
| 434 | presenter()->meta->store($name, $content); |
||
| 435 | } |
||
| 436 | } |
||
| 437 | } |
||
| 438 | |||
| 439 | $moduleAssets = [ |
||
| 440 | 'app', |
||
| 441 | 'module', |
||
| 442 | modules()->top()->getParameter(), |
||
| 443 | ]; |
||
| 444 | |||
| 445 | // Autoload Assets |
||
| 446 | presenter()->assets->loadCss($moduleAssets); |
||
| 447 | presenter()->assets->loadJs($moduleAssets); |
||
| 448 | |||
| 449 | /** |
||
| 450 | * Autoload Page Assets |
||
| 451 | */ |
||
| 452 | if ($pagePresets->offsetExists('assets')) { |
||
| 453 | presenter()->assets->autoload($pagePresets->assets); |
||
| 454 | } |
||
| 455 | |||
| 456 | if (presenter()->page->file instanceof \SplFileInfo) { |
||
| 457 | $pageDir = presenter()->page->file->getRealPath(); |
||
| 458 | $pageDir = str_replace('.' . pathinfo($pageDir, PATHINFO_EXTENSION), '', $pageDir); |
||
| 459 | |||
| 460 | $pageDirParts = explode('pages' . DIRECTORY_SEPARATOR, |
||
| 461 | str_replace(['/', '\\'], DIRECTORY_SEPARATOR, $pageDir)); |
||
| 462 | $pageDir = end($pageDirParts); |
||
| 463 | |||
| 464 | presenter()->assets->addFilePath(reset($pageDirParts) . 'pages' . DIRECTORY_SEPARATOR); |
||
| 465 | |||
| 466 | $pageDir = rtrim($pageDir, DIRECTORY_SEPARATOR); |
||
| 467 | $pageDirParts = explode(DIRECTORY_SEPARATOR, $pageDir); |
||
| 468 | |||
| 469 | $totalParts = count($pageDirParts); |
||
| 470 | |||
| 471 | for ($i = 0; $i < $totalParts; $i++) { |
||
| 472 | $pageAssets[] = implode(DIRECTORY_SEPARATOR, array_slice($pageDirParts, 0, ($totalParts - $i))); |
||
| 473 | } |
||
| 474 | |||
| 475 | $pageAssets[] = implode(DIRECTORY_SEPARATOR, [end($pageAssets), end($pageAssets)]); |
||
| 476 | |||
| 477 | // Autoload Assets |
||
| 478 | presenter()->assets->loadCss($pageAssets); |
||
| 479 | presenter()->assets->loadJs($pageAssets); |
||
| 480 | } |
||
| 481 | |||
| 482 | /** |
||
| 483 | * Sets Page Meta |
||
| 484 | */ |
||
| 485 | if ($pagePresets->offsetExists('title')) { |
||
| 486 | presenter()->meta->title->append(language()->getLine($pagePresets->title)); |
||
| 487 | } |
||
| 488 | |||
| 489 | if ($pagePresets->offsetExists('pageTitle')) { |
||
| 490 | presenter()->meta->title->replace(language()->getLine($pagePresets->pageTitle)); |
||
| 491 | } |
||
| 492 | |||
| 493 | if ($pagePresets->offsetExists('browserTitle')) { |
||
| 494 | presenter()->meta->title->replace(language()->getLine($pagePresets->browserTitle)); |
||
| 495 | } |
||
| 496 | |||
| 497 | if ($pagePresets->offsetExists('meta')) { |
||
| 498 | foreach ($pagePresets->meta as $name => $content) { |
||
| 499 | presenter()->meta->store($name, $content); |
||
| 500 | } |
||
| 501 | } |
||
| 502 | |||
| 503 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
| 504 | parser()->loadFile($layout->getRealPath()); |
||
| 505 | |||
| 506 | $htmlOutput = parser()->parse(); |
||
| 507 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
| 508 | |||
| 509 | $this->document->loadHTML($htmlOutput); |
||
| 510 | } |
||
| 511 | } else { |
||
| 512 | output()->sendError(204, language()->getLine('E_THEME_NOT_FOUND', [$theme])); |
||
| 513 | } |
||
| 514 | } elseif (presenter()->theme instanceof Theme) { |
||
| 515 | /** |
||
| 516 | * Autoload Theme Assets |
||
| 517 | */ |
||
| 518 | presenter()->theme->load(); |
||
| 519 | |||
| 520 | if (false !== ($modulePresets = modules()->top()->getPresets())) { |
||
| 521 | |||
| 522 | /** |
||
| 523 | * Autoload Module Assets |
||
| 524 | */ |
||
| 525 | if ($modulePresets->offsetExists('assets')) { |
||
| 526 | presenter()->assets->autoload($modulePresets->assets); |
||
| 527 | } |
||
| 528 | |||
| 529 | /** |
||
| 530 | * Sets Module Meta |
||
| 531 | */ |
||
| 532 | if ($modulePresets->offsetExists('title')) { |
||
| 533 | presenter()->meta->title->append(language()->getLine($modulePresets->title)); |
||
| 534 | } |
||
| 535 | |||
| 536 | if ($modulePresets->offsetExists('pageTitle')) { |
||
| 537 | presenter()->meta->title->replace(language()->getLine($modulePresets->pageTitle)); |
||
| 538 | } |
||
| 539 | |||
| 540 | if ($modulePresets->offsetExists('browserTitle')) { |
||
| 541 | presenter()->meta->title->replace(language()->getLine($modulePresets->browserTitle)); |
||
| 542 | } |
||
| 543 | |||
| 544 | if ($modulePresets->offsetExists('meta')) { |
||
| 545 | foreach ($modulePresets->meta as $name => $content) { |
||
| 546 | presenter()->meta->store($name, $content); |
||
| 547 | } |
||
| 548 | } |
||
| 549 | } |
||
| 550 | |||
| 551 | $moduleAssets = [ |
||
| 552 | 'app', |
||
| 553 | 'module', |
||
| 554 | modules()->top()->getParameter(), |
||
| 555 | ]; |
||
| 556 | |||
| 557 | // Autoload Assets |
||
| 558 | presenter()->assets->loadCss($moduleAssets); |
||
| 559 | presenter()->assets->loadJs($moduleAssets); |
||
| 560 | |||
| 561 | /** |
||
| 562 | * Autoload Controller Assets |
||
| 563 | */ |
||
| 564 | $controllerFilename = str_replace([modules()->top()->getDir('Controllers'), '.php'], '', |
||
| 565 | controller()->getFileInfo()->getRealPath()); |
||
| 566 | $controllerFilename = dash($controllerFilename); |
||
| 567 | $controllerAssets[] = $controllerFilename; |
||
| 568 | $controllerAssets[] = implode('/', [ |
||
| 569 | $controllerFilename, |
||
| 570 | controller()->getRequestMethod(), |
||
| 571 | ]); |
||
| 572 | |||
| 573 | presenter()->assets->loadCss($controllerAssets); |
||
| 574 | presenter()->assets->loadJs($controllerAssets); |
||
| 575 | |||
| 576 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
| 577 | parser()->loadFile($layout->getRealPath()); |
||
| 578 | |||
| 579 | $htmlOutput = parser()->parse(); |
||
| 580 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
| 581 | |||
| 582 | $this->document->loadHTML($htmlOutput); |
||
| 583 | } |
||
| 584 | } elseif (false !== ($theme = presenter()->getConfig('theme'))) { |
||
| 585 | if (modules()->top()->hasTheme($theme)) { |
||
| 586 | presenter()->setTheme($theme); |
||
| 587 | |||
| 588 | /** |
||
| 589 | * Autoload Theme Assets |
||
| 590 | */ |
||
| 591 | presenter()->theme->load(); |
||
| 592 | |||
| 593 | if (false !== ($modulePresets = modules()->top()->getPresets())) { |
||
| 594 | |||
| 595 | /** |
||
| 596 | * Autoload Module Assets |
||
| 597 | */ |
||
| 598 | if ($modulePresets->offsetExists('assets')) { |
||
| 599 | presenter()->assets->autoload($modulePresets->assets); |
||
| 600 | } |
||
| 601 | |||
| 602 | /** |
||
| 603 | * Sets Module Meta |
||
| 604 | */ |
||
| 605 | if ($modulePresets->offsetExists('title')) { |
||
| 606 | presenter()->meta->title->append(language()->getLine($modulePresets->title)); |
||
| 607 | } |
||
| 608 | |||
| 609 | if ($modulePresets->offsetExists('pageTitle')) { |
||
| 610 | presenter()->meta->title->replace(language()->getLine($modulePresets->pageTitle)); |
||
| 611 | } |
||
| 612 | |||
| 613 | if ($modulePresets->offsetExists('browserTitle')) { |
||
| 614 | presenter()->meta->title->replace(language()->getLine($modulePresets->browserTitle)); |
||
| 615 | } |
||
| 616 | |||
| 617 | if ($modulePresets->offsetExists('meta')) { |
||
| 618 | foreach ($modulePresets->meta as $name => $content) { |
||
| 619 | presenter()->meta->store($name, $content); |
||
| 620 | } |
||
| 621 | } |
||
| 622 | } |
||
| 623 | |||
| 624 | $moduleAssets = [ |
||
| 625 | 'app', |
||
| 626 | 'module', |
||
| 627 | modules()->top()->getParameter(), |
||
| 628 | ]; |
||
| 629 | |||
| 630 | // Autoload Assets |
||
| 631 | presenter()->assets->loadCss($moduleAssets); |
||
| 632 | presenter()->assets->loadJs($moduleAssets); |
||
| 633 | |||
| 634 | /** |
||
| 635 | * Autoload Controller Assets |
||
| 636 | */ |
||
| 637 | $controllerFilename = str_replace([modules()->top()->getDir('Controllers'), '.php'], '', |
||
| 638 | controller()->getFileInfo()->getRealPath()); |
||
| 639 | $controllerFilename = dash($controllerFilename); |
||
| 640 | $controllerAssets[] = $controllerFilename; |
||
| 641 | $controllerAssets[] = implode('/', [ |
||
| 642 | $controllerFilename, |
||
| 643 | controller()->getRequestMethod(), |
||
| 644 | ]); |
||
| 645 | |||
| 646 | if (false !== ($layout = presenter()->theme->getLayout())) { |
||
| 647 | parser()->loadFile($layout->getRealPath()); |
||
| 648 | |||
| 649 | $htmlOutput = parser()->parse(); |
||
| 650 | $htmlOutput = presenter()->assets->parseSourceCode($htmlOutput); |
||
| 651 | |||
| 652 | $this->document->loadHTML($htmlOutput); |
||
| 653 | } |
||
| 654 | } else { |
||
| 655 | output()->sendError(204, language()->getLine('E_THEME_NOT_FOUND', [$theme])); |
||
| 656 | } |
||
| 657 | } else { |
||
| 658 | $this->document->find('body')->append(presenter()->partials->__get('content')); |
||
| 659 | } |
||
| 660 | |||
| 661 | /** |
||
| 662 | * Set Document Meta Title |
||
| 663 | */ |
||
| 664 | if (presenter()->meta->title instanceof Meta\Title) { |
||
| 665 | $this->document->title->text(presenter()->meta->title->__toString()); |
||
| 666 | } |
||
| 667 | |||
| 668 | /** |
||
| 669 | * Injecting Meta Opengraph |
||
| 670 | */ |
||
| 671 | if (presenter()->meta->opengraph instanceof Meta\Opengraph) { |
||
| 672 | // set opengraph title |
||
| 673 | if (presenter()->meta->title instanceof Meta\Title) { |
||
| 674 | presenter()->meta->opengraph->setTitle(presenter()->meta->title->__toString()); |
||
| 675 | } |
||
| 676 | |||
| 677 | // set opengraph site name |
||
| 678 | if (presenter()->exists('siteName')) { |
||
| 679 | presenter()->meta->opengraph->setSiteName(presenter()->offsetGet('siteName')); |
||
| 680 | } |
||
| 681 | |||
| 682 | if (presenter()->meta->opengraph->count()) { |
||
| 683 | $htmlElement = $this->document->getElementsByTagName('html')->item(0); |
||
| 684 | $htmlElement->setAttribute('prefix', 'og: ' . presenter()->meta->opengraph->prefix); |
||
| 685 | |||
| 686 | if (presenter()->meta->opengraph->exists('og:type') === false) { |
||
| 687 | presenter()->meta->opengraph->setType('website'); |
||
| 688 | } |
||
| 689 | |||
| 690 | $opengraph = presenter()->meta->opengraph->getArrayCopy(); |
||
| 691 | |||
| 692 | foreach ($opengraph as $tag) { |
||
| 693 | $this->document->metaNodes->createElement($tag->attributes->getArrayCopy()); |
||
| 694 | } |
||
| 695 | } |
||
| 696 | } |
||
| 697 | |||
| 698 | if (presenter()->meta->count()) { |
||
| 699 | $meta = presenter()->meta->getArrayCopy(); |
||
| 700 | |||
| 701 | foreach ($meta as $tag) { |
||
| 702 | $this->document->metaNodes->createElement($tag->attributes->getArrayCopy()); |
||
| 703 | } |
||
| 704 | } |
||
| 705 | |||
| 706 | /** |
||
| 707 | * Inject body attributes |
||
| 708 | */ |
||
| 709 | $body = $this->document->getElementsByTagName('body'); |
||
| 710 | $body->item(0)->setAttribute('module', modules()->top()->getParameter()); |
||
| 711 | |||
| 712 | /** |
||
| 713 | * Injecting Single Sign-On (SSO) iFrame |
||
| 714 | */ |
||
| 715 | if (services()->has('user')) { |
||
| 716 | $iframe = services()->get('user')->getIframeCode(); |
||
| 717 | |||
| 718 | if ( ! empty($iframe)) { |
||
| 719 | $this->document->find('body')->append($iframe); |
||
| 720 | } |
||
| 721 | } |
||
| 722 | |||
| 723 | if (input()->env('DEBUG_STAGE') === 'DEVELOPER' and |
||
| 724 | presenter()->getConfig('debugToolBar') === true and |
||
| 725 | services()->has('profiler') |
||
| 726 | ) { |
||
| 727 | $this->document->find('body')->append((new Toolbar())->__toString()); |
||
| 728 | } |
||
| 729 | |||
| 730 | /** |
||
| 731 | * Injecting Progressive Web Application (PWA) Manifest |
||
| 732 | */ |
||
| 733 | $this->document->linkNodes->createElement([ |
||
| 734 | 'rel' => 'manifest', |
||
| 735 | 'href' => '/manifest.json', |
||
| 736 | ]); |
||
| 737 | |||
| 738 | $htmlOutput = $this->document->saveHTML(); |
||
| 739 | |||
| 740 | // Uglify Output |
||
| 741 | if ($this->config->output[ 'uglify' ] === true) { |
||
| 742 | $htmlOutput = preg_replace( |
||
| 743 | [ |
||
| 744 | '/\>[^\S ]+/s', // strip whitespaces after tags, except space |
||
| 745 | '/[^\S ]+\</s', // strip whitespaces before tags, except space |
||
| 746 | '/(\s)+/s', // shorten multiple whitespace sequences |
||
| 747 | '/<!--(.|\s)*?-->/', // Remove HTML comments |
||
| 748 | '/<!--(.*)-->/Uis', |
||
| 749 | "/[[:blank:]]+/", |
||
| 750 | ], |
||
| 751 | [ |
||
| 752 | '>', |
||
| 753 | '<', |
||
| 754 | '\\1', |
||
| 755 | '', |
||
| 756 | '', |
||
| 757 | ' ', |
||
| 758 | ], |
||
| 759 | str_replace(["\n", "\r", "\t"], '', $htmlOutput)); |
||
| 760 | } |
||
| 761 | |||
| 762 | // Beautify Output |
||
| 763 | if ($this->config->output[ 'beautify' ] === true) { |
||
| 764 | $beautifier = new Html\Dom\Beautifier(); |
||
| 765 | $htmlOutput = $beautifier->format($htmlOutput); |
||
| 766 | } |
||
| 767 | |||
| 768 | if (profiler() !== false) { |
||
| 769 | profiler()->watch('Ending View Rendering'); |
||
| 770 | } |
||
| 771 | |||
| 772 | return $htmlOutput; |
||
| 773 | } |
||
| 774 | } |
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"], you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths