wikimedia/mediawiki-core

View on GitHub
includes/ExternalLinks/LinkFilter.php

Summary

Maintainability
F
3 days
Test Coverage

Function indexifyHost has a Cognitive Complexity of 32 (exceeds 5 allowed). Consider refactoring.
Open

    private static function indexifyHost( $host, $reverse = true ) {
        // Canonicalize.
        $host = rawurldecode( $host );
        if ( $host !== '' ) {
            $tmp = idn_to_utf8( $host );
Severity: Minor
Found in includes/ExternalLinks/LinkFilter.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

File LinkFilter.php has 336 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php
/**
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
Severity: Minor
Found in includes/ExternalLinks/LinkFilter.php - About 4 hrs to fix

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

        public static function makeLikeArray( $filterEntry, $protocol = 'http://' ) {
            $services = MediaWikiServices::getInstance();
            $db = $services->getConnectionProvider()->getReplicaDatabase();
            $likeDomain = [];
            $likePath = [];
    Severity: Minor
    Found in includes/ExternalLinks/LinkFilter.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

    Method indexifyHost has 62 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        private static function indexifyHost( $host, $reverse = true ) {
            // Canonicalize.
            $host = rawurldecode( $host );
            if ( $host !== '' ) {
                $tmp = idn_to_utf8( $host );
    Severity: Major
    Found in includes/ExternalLinks/LinkFilter.php - About 2 hrs to fix

      Function makeIndexes has a Cognitive Complexity of 17 (exceeds 5 allowed). Consider refactoring.
      Open

          public static function makeIndexes( $url, $reverseDomain = true ) {
              // NOTE: refreshExternallinksIndex.php assumes that only protocol-relative URLs return more
              // than one index, and that the indexes for protocol-relative URLs only vary in the "http://"
              // versus "https://" prefix. If you change that, you'll likely need to update
              // refreshExternallinksIndex.php accordingly.
      Severity: Minor
      Found in includes/ExternalLinks/LinkFilter.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

      Method makeLikeArray has 55 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public static function makeLikeArray( $filterEntry, $protocol = 'http://' ) {
              $services = MediaWikiServices::getInstance();
              $db = $services->getConnectionProvider()->getReplicaDatabase();
              $likeDomain = [];
              $likePath = [];
      Severity: Major
      Found in includes/ExternalLinks/LinkFilter.php - About 2 hrs to fix

        Function getQueryConditions has a Cognitive Complexity of 16 (exceeds 5 allowed). Consider refactoring.
        Open

            public static function getQueryConditions( $filterEntry, array $options = [] ) {
                $options += [
                    'protocol' => [ 'http://', 'https://' ],
                    'oneWildcard' => false,
                    'db' => null,
        Severity: Minor
        Found in includes/ExternalLinks/LinkFilter.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

        Method getQueryConditions has 52 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function getQueryConditions( $filterEntry, array $options = [] ) {
                $options += [
                    'protocol' => [ 'http://', 'https://' ],
                    'oneWildcard' => false,
                    'db' => null,
        Severity: Major
        Found in includes/ExternalLinks/LinkFilter.php - About 2 hrs to fix

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

              public static function makeIndexes( $url, $reverseDomain = true ) {
                  // NOTE: refreshExternallinksIndex.php assumes that only protocol-relative URLs return more
                  // than one index, and that the indexes for protocol-relative URLs only vary in the "http://"
                  // versus "https://" prefix. If you change that, you'll likely need to update
                  // refreshExternallinksIndex.php accordingly.
          Severity: Minor
          Found in includes/ExternalLinks/LinkFilter.php - About 1 hr to fix

            Function getProtocolPrefix has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
            Open

                public static function getProtocolPrefix( $protocol ) {
                    // Find the right prefix
                    $urlProtocols = MediaWikiServices::getInstance()->getMainConfig()
                                                     ->get( MainConfigNames::UrlProtocols );
                    if ( $protocol && !in_array( $protocol, $urlProtocols ) ) {
            Severity: Minor
            Found in includes/ExternalLinks/LinkFilter.php - About 55 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

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

                public static function reverseIndexes( $domainIndex ) {
                    $bits = MediaWikiServices::getInstance()->getUrlUtils()->parse( $domainIndex );
                    if ( !$bits ) {
                        return '';
                    }
            Severity: Minor
            Found in includes/ExternalLinks/LinkFilter.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 too many return statements within this method.
            Open

                                return 'V6.' .
                                    substr( implode( '.', explode( ':', IPUtils::sanitizeIP( "{$cutIp}:1" ) ) ), 0, -1 ) .
                                    '*.';
            Severity: Major
            Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

              Avoid too many return statements within this method.
              Open

                                      return '[' . IPUtils::sanitizeIP( "{$cutIp}:1" ) . ']';
              Severity: Major
              Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

                Avoid too many return statements within this method.
                Open

                                return $host;
                Severity: Major
                Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

                  Avoid too many return statements within this method.
                  Open

                              return $host;
                  Severity: Major
                  Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

                    Avoid too many return statements within this method.
                    Open

                                return 'V4.' . implode( '.', array_map( static function ( $v ) {
                                    return $v === '*' ? $v : (int)$v;
                                }, explode( '.', $host ) ) ) . '.';
                    Severity: Major
                    Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

                      Avoid too many return statements within this method.
                      Open

                                  return implode( '.', array_reverse( explode( '.', $host ) ) ) . '.';
                      Severity: Major
                      Found in includes/ExternalLinks/LinkFilter.php - About 30 mins to fix

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

                            public static function getIndexedUrlsNonReversed( $urls ) {
                                $newLinks = [];
                                foreach ( $urls as $url ) {
                                    $indexes = self::makeIndexes( $url, false );
                                    if ( !$indexes ) {
                        Severity: Minor
                        Found in includes/ExternalLinks/LinkFilter.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

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

                            private static function reverseDomain( $domain ) {
                                if ( substr( $domain, 0, 3 ) === 'V6.' ) {
                                    $ipv6 = str_replace( '.', ':', trim( substr( $domain, 3 ), '.' ) );
                                    if ( IPUtils::isValid( $ipv6 ) ) {
                                        return '[' . $ipv6 . ']';
                        Severity: Minor
                        Found in includes/ExternalLinks/LinkFilter.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