wikimedia/mediawiki-core

View on GitHub
includes/specials/SpecialSearch.php

Summary

Maintainability
F
4 days
Test Coverage

File SpecialSearch.php has 588 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * Implements Special:Search
 *
 * Copyright © 2004 Brooke Vibber <bvibber@wikimedia.org>
Severity: Major
Found in includes/specials/SpecialSearch.php - About 1 day to fix

    Method showResults has 152 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function showResults( $term ) {
            if ( $this->searchEngineType !== null ) {
                $this->setExtraParam( 'srbackend', $this->searchEngineType );
            }
    
    
    Severity: Major
    Found in includes/specials/SpecialSearch.php - About 6 hrs to fix

      Function showResults has a Cognitive Complexity of 28 (exceeds 5 allowed). Consider refactoring.
      Open

          public function showResults( $term ) {
              if ( $this->searchEngineType !== null ) {
                  $this->setExtraParam( 'srbackend', $this->searchEngineType );
              }
      
      
      Severity: Minor
      Found in includes/specials/SpecialSearch.php - About 4 hrs 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

      SpecialSearch has 21 functions (exceeds 20 allowed). Consider refactoring.
      Open

      class SpecialSearch extends SpecialPage {
          /**
           * Current search profile. Search profile is just a name that identifies
           * the active search tab on the search page (content, discussions...)
           * For users tt replaces the set of enabled namespaces from the query
      Severity: Minor
      Found in includes/specials/SpecialSearch.php - About 2 hrs to fix

        Method load has 54 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function load() {
                $this->loadStatus = new Status();
        
                $request = $this->getRequest();
                $this->searchEngineType = $request->getVal( 'srbackend' );
        Severity: Major
        Found in includes/specials/SpecialSearch.php - About 2 hrs to fix

          Function load has a Cognitive Complexity of 15 (exceeds 5 allowed). Consider refactoring.
          Open

              public function load() {
                  $this->loadStatus = new Status();
          
                  $request = $this->getRequest();
                  $this->searchEngineType = $request->getVal( 'srbackend' );
          Severity: Minor
          Found in includes/specials/SpecialSearch.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

          Method execute has 41 lines of code (exceeds 25 allowed). Consider refactoring.
          Open

              public function execute( $par ) {
                  $request = $this->getRequest();
                  $out = $this->getOutput();
          
                  // Fetch the search term
          Severity: Minor
          Found in includes/specials/SpecialSearch.php - About 1 hr to fix

            Function execute has a Cognitive Complexity of 13 (exceeds 5 allowed). Consider refactoring.
            Open

                public function execute( $par ) {
                    $request = $this->getRequest();
                    $out = $this->getOutput();
            
                    // Fetch the search term
            Severity: Minor
            Found in includes/specials/SpecialSearch.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

            Method setupPage has 38 lines of code (exceeds 25 allowed). Consider refactoring.
            Open

                protected function setupPage( $term ) {
                    $out = $this->getOutput();
            
                    $this->setHeaders();
                    $this->outputHeader();
            Severity: Minor
            Found in includes/specials/SpecialSearch.php - About 1 hr to fix

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

                  protected function getSearchProfiles() {
                      // Builds list of Search Types (profiles)
                      $nsAllSet = array_keys( $this->searchConfig->searchableNamespaces() );
                      $defaultNs = $this->searchConfig->defaultNamespaces();
                      $profiles = [
              Severity: Minor
              Found in includes/specials/SpecialSearch.php - About 1 hr to fix

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

                        SearchEngineConfig $searchConfig,
                        SearchEngineFactory $searchEngineFactory,
                        NamespaceInfo $nsInfo,
                        IContentHandlerFactory $contentHandlerFactory,
                        InterwikiLookup $interwikiLookup,
                Severity: Major
                Found in includes/specials/SpecialSearch.php - About 1 hr to fix

                  Method showCreateLink has 32 lines of code (exceeds 25 allowed). Consider refactoring.
                  Open

                      protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
                          // show direct page/create link if applicable
                  
                          // Check DBkey !== '' in case of fragment link only.
                          if ( $title === null || $title->getDBkey() === ''
                  Severity: Minor
                  Found in includes/specials/SpecialSearch.php - About 1 hr to fix

                    Function showCreateLink has a Cognitive Complexity of 11 (exceeds 5 allowed). Consider refactoring.
                    Open

                        protected function showCreateLink( $title, $num, $titleMatches, $textMatches ) {
                            // show direct page/create link if applicable
                    
                            // Check DBkey !== '' in case of fragment link only.
                            if ( $title === null || $title->getDBkey() === ''
                    Severity: Minor
                    Found in includes/specials/SpecialSearch.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 prevNextLinks has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
                    Open

                        private function prevNextLinks(
                            ?int $totalRes,
                            ?ISearchResultSet $textMatches,
                            string $term,
                            string $class,
                    Severity: Minor
                    Found in includes/specials/SpecialSearch.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

                    Consider simplifying this complex logical expression.
                    Open

                            if ( $title === null || $title->getDBkey() === ''
                                || ( $titleMatches !== null && $titleMatches->searchContainedSyntax() )
                                || ( $textMatches !== null && $textMatches->searchContainedSyntax() )
                            ) {
                                // invalid title
                    Severity: Major
                    Found in includes/specials/SpecialSearch.php - About 40 mins to fix

                      Method prevNextLinks has 5 arguments (exceeds 4 allowed). Consider refactoring.
                      Open

                              ?int $totalRes,
                              ?ISearchResultSet $textMatches,
                              string $term,
                              string $class,
                              OutputPage $out
                      Severity: Minor
                      Found in includes/specials/SpecialSearch.php - About 35 mins to fix

                        Avoid too many return statements within this method.
                        Open

                                return $url ?? $title->getFullUrlForRedirect();
                        Severity: Major
                        Found in includes/specials/SpecialSearch.php - About 30 mins to fix

                          Function saveNamespaces has a Cognitive Complexity of 6 (exceeds 5 allowed). Consider refactoring.
                          Open

                              protected function saveNamespaces() {
                                  $user = $this->getUser();
                                  $request = $this->getRequest();
                          
                                  if ( $user->isRegistered() &&
                          Severity: Minor
                          Found in includes/specials/SpecialSearch.php - About 25 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

                          There are no issues that match your filters.

                          Category
                          Status