wikimedia/mediawiki-core

View on GitHub
includes/search/searchwidgets/FullSearchResultWidget.php

Summary

Maintainability
D
1 day
Test Coverage

File FullSearchResultWidget.php has 301 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Search\SearchWidgets;

use File;
Severity: Minor
Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 3 hrs to fix

    Method render has 66 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function render( SearchResult $result, $position ) {
            // If the page doesn't *exist*... our search index is out of date.
            // The least confusing at this point is to drop the result.
            // You may get less results, but... on well. :P
            if ( $result->isBrokenTitle() || $result->isMissingRevision() ) {
    Severity: Major
    Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 2 hrs to fix

      Method generateFileHtml has 35 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          protected function generateFileHtml( SearchResult $result ) {
              $title = $result->getTitle();
              // don't assume that result is a valid title; e.g. could be an interwiki link target
              if ( $title === null || !$title->canExist() ) {
                  return [ '', null, null ];
      Severity: Minor
      Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 1 hr to fix

        Method generateThumbnailHtml has 34 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            private function generateThumbnailHtml( SearchResult $result, SearchResultThumbnail $thumbnail = null ): ?string {
                $title = $result->getTitle();
                // don't assume that result is a valid title; e.g. could be an interwiki link target
                if ( $title === null || !$title->canExist() ) {
                    return null;
        Severity: Minor
        Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 1 hr to fix

          Function render has a Cognitive Complexity of 10 (exceeds 5 allowed). Consider refactoring.
          Open

              public function render( SearchResult $result, $position ) {
                  // If the page doesn't *exist*... our search index is out of date.
                  // The least confusing at this point is to drop the result.
                  // You may get less results, but... on well. :P
                  if ( $result->isBrokenTitle() || $result->isMissingRevision() ) {
          Severity: Minor
          Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 1 hr to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Function generateThumbnailHtml has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function generateThumbnailHtml( SearchResult $result, SearchResultThumbnail $thumbnail = null ): ?string {
                  $title = $result->getTitle();
                  // don't assume that result is a valid title; e.g. could be an interwiki link target
                  if ( $title === null || !$title->canExist() ) {
                      return null;
          Severity: Minor
          Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 45 mins to fix

          Cognitive Complexity

          Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

          A method's cognitive complexity is based on a few simple rules:

          • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
          • Code is considered more complex for each "break in the linear flow of the code"
          • Code is considered more complex when "flow breaking structures are nested"

          Further reading

          Method __construct has 6 arguments (exceeds 4 allowed). Consider refactoring.
          Open

                  SpecialSearch $specialPage,
                  LinkRenderer $linkRenderer,
                  HookContainer $hookContainer,
                  RepoGroup $repoGroup,
                  SearchResultThumbnailProvider $thumbnailProvider,
          Severity: Minor
          Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 45 mins to fix

            Function generateFileHtml has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
            Open

                protected function generateFileHtml( SearchResult $result ) {
                    $title = $result->getTitle();
                    // don't assume that result is a valid title; e.g. could be an interwiki link target
                    if ( $title === null || !$title->canExist() ) {
                        return [ '', null, null ];
            Severity: Minor
            Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 35 mins to fix

            Cognitive Complexity

            Cognitive Complexity is a measure of how difficult a unit of code is to intuitively understand. Unlike Cyclomatic Complexity, which determines how difficult your code will be to test, Cognitive Complexity tells you how difficult your code will be to read and comprehend.

            A method's cognitive complexity is based on a few simple rules:

            • Code is not considered more complex when it uses shorthand that the language provides for collapsing multiple statements into one
            • Code is considered more complex for each "break in the linear flow of the code"
            • Code is considered more complex when "flow breaking structures are nested"

            Further reading

            Avoid too many return statements within this method.
            Open

                    return [
                        $html,
                        $this->specialPage->msg( 'parentheses' )->rawParams( $img->getShortDesc() )->escaped(),
                        $this->generateThumbnailHtml( $result, $thumbnail )
                    ];
            Severity: Major
            Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                              return $thumb->toHtml( [
                                  'desc-link' => true,
                                  'loading' => 'lazy',
                                  'alt' => $this->specialPage->msg( 'search-thumbnail-alt' )->params( $title ),
                              ] );
              Severity: Major
              Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                        return $this->generateThumbnailPlaceholderHtml();
                Severity: Major
                Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $thumb->toHtml( [
                                  'desc-link' => true,
                                  'custom-title-link' => $title,
                                  'loading' => 'lazy',
                                  'alt' => $this->specialPage->msg( 'search-thumbnail-alt' )->params( $title ),
                  Severity: Major
                  Found in includes/search/searchwidgets/FullSearchResultWidget.php - About 30 mins to fix

                    There are no issues that match your filters.

                    Category
                    Status