wikimedia/mediawiki-core

View on GitHub
includes/Rest/Handler/SearchHandler.php

Summary

Maintainability
C
1 day
Test Coverage

Function buildPageObjects has a Cognitive Complexity of 19 (exceeds 5 allowed). Consider refactoring.
Open

    private function buildPageObjects( array $searchResponse ): array {
        $pageInfos = [];
        foreach ( $searchResponse as $response ) {
            $isSearchResult = $response instanceof SearchResult;
            if ( $isSearchResult ) {
Severity: Minor
Found in includes/Rest/Handler/SearchHandler.php - About 2 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

File SearchHandler.php has 257 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Rest\Handler;

use InvalidArgumentException;
Severity: Minor
Found in includes/Rest/Handler/SearchHandler.php - About 2 hrs to fix

    Function getSearchResultsOrThrow has a Cognitive Complexity of 14 (exceeds 5 allowed). Consider refactoring.
    Open

        private function getSearchResultsOrThrow( $results ) {
            if ( $results ) {
                if ( $results instanceof StatusValue ) {
                    $status = $results;
                    if ( !$status->isOK() ) {
    Severity: Minor
    Found in includes/Rest/Handler/SearchHandler.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 28 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public function execute() {
            $searchEngine = $this->createSearchEngine();
            $pageInfos = $this->doSearch( $searchEngine );
    
            // We can only pass validated "real" PageIdentities to our hook handlers below
    Severity: Minor
    Found in includes/Rest/Handler/SearchHandler.php - About 1 hr to fix

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

              Config $config,
              SearchEngineFactory $searchEngineFactory,
              SearchEngineConfig $searchEngineConfig,
              SearchResultThumbnailProvider $searchResultThumbnailProvider,
              PermissionManager $permissionManager,
      Severity: Major
      Found in includes/Rest/Handler/SearchHandler.php - About 1 hr to fix

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

            public function execute() {
                $searchEngine = $this->createSearchEngine();
                $pageInfos = $this->doSearch( $searchEngine );
        
                // We can only pass validated "real" PageIdentities to our hook handlers below
        Severity: Minor
        Found in includes/Rest/Handler/SearchHandler.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