wikimedia/mediawiki-core

View on GitHub
includes/search/SearchHighlighter.php

Summary

Maintainability
F
4 days
Test Coverage

Function highlightText has a Cognitive Complexity of 96 (exceeds 5 allowed). Consider refactoring.
Open

    public function highlightText(
        $text,
        $terms,
        $contextlines = self::DEFAULT_CONTEXT_LINES,
        $contextchars = self::DEFAULT_CONTEXT_CHARS
Severity: Minor
Found in includes/search/SearchHighlighter.php - About 1 day 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 highlightText has 192 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    public function highlightText(
        $text,
        $terms,
        $contextlines = self::DEFAULT_CONTEXT_LINES,
        $contextchars = self::DEFAULT_CONTEXT_CHARS
Severity: Major
Found in includes/search/SearchHighlighter.php - About 7 hrs to fix

    File SearchHighlighter.php has 381 lines of code (exceeds 250 allowed). Consider refactoring.
    Open

    <?php
    /**
     * Basic search engine highlighting
     *
     * This program is free software; you can redistribute it and/or modify
    Severity: Minor
    Found in includes/search/SearchHighlighter.php - About 5 hrs to fix

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

          private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
              if ( $linesleft == 0 ) {
                  return; // nothing to do
              }
              foreach ( $extracts as $index => $line ) {
      Severity: Minor
      Found in includes/search/SearchHighlighter.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 process has 29 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
              if ( $linesleft == 0 ) {
                  return; // nothing to do
              }
              foreach ( $extracts as $index => $line ) {
      Severity: Minor
      Found in includes/search/SearchHighlighter.php - About 1 hr to fix

        Method highlightSimple has 28 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public function highlightSimple(
                $text,
                $terms,
                $contextlines = self::DEFAULT_CONTEXT_LINES,
                $contextchars = self::DEFAULT_CONTEXT_CHARS
        Severity: Minor
        Found in includes/search/SearchHighlighter.php - About 1 hr to fix

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

              public function highlightSimple(
                  $text,
                  $terms,
                  $contextlines = self::DEFAULT_CONTEXT_LINES,
                  $contextchars = self::DEFAULT_CONTEXT_CHARS
          Severity: Minor
          Found in includes/search/SearchHighlighter.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 position has a Cognitive Complexity of 8 (exceeds 5 allowed). Consider refactoring.
          Open

              private function position( $text, $point, $offset = 0 ) {
                  $tolerance = 10;
                  $s = max( 0, $point - $tolerance );
                  $l = min( strlen( $text ), $point + $tolerance ) - $s;
                  $m = [];
          Severity: Minor
          Found in includes/search/SearchHighlighter.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

          Avoid deeply nested control flow statements.
          Open

                                      if (
                                          MediaWikiServices::getInstance()->getContentLanguage()->
                                          getNsIndex( $ns ) !== NS_FILE
                                      ) {
                                          break;
          Severity: Major
          Found in includes/search/SearchHighlighter.php - About 45 mins to fix

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

                private function process( $pattern, $extracts, &$linesleft, &$contextchars, &$out, &$offsets ) {
            Severity: Minor
            Found in includes/search/SearchHighlighter.php - About 45 mins to fix

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

                  private function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) {
              Severity: Minor
              Found in includes/search/SearchHighlighter.php - About 35 mins to fix

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

                    private function extract( $text, $start, $end, &$posStart = null, &$posEnd = null ) {
                        if ( $start != 0 ) {
                            $start = $this->position( $text, $start, 1 );
                        }
                        if ( $end >= strlen( $text ) ) {
                Severity: Minor
                Found in includes/search/SearchHighlighter.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

                There are no issues that match your filters.

                Category
                Status