wikimedia/mediawiki-core

View on GitHub
includes/utils/UrlUtils.php

Summary

Maintainability
D
2 days
Test Coverage

Function expand has a Cognitive Complexity of 33 (exceeds 5 allowed). Consider refactoring.
Open

    public function expand( string $url, $defaultProto = PROTO_FALLBACK ): ?string {
        if ( $defaultProto === PROTO_CANONICAL ) {
            $serverUrl = $this->canonicalServer;
        } elseif ( $defaultProto === PROTO_INTERNAL ) {
            $serverUrl = $this->internalServer;
Severity: Minor
Found in includes/utils/UrlUtils.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

Function removeDotSegments has a Cognitive Complexity of 26 (exceeds 5 allowed). Consider refactoring.
Open

    public static function removeDotSegments( string $urlPath ): string {
        $output = '';
        $inputOffset = 0;
        $inputLength = strlen( $urlPath );

Severity: Minor
Found in includes/utils/UrlUtils.php - About 3 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 UrlUtils.php has 283 lines of code (exceeds 250 allowed). Consider refactoring.
Open

<?php

namespace MediaWiki\Utils;

use BadMethodCallException;
Severity: Minor
Found in includes/utils/UrlUtils.php - About 2 hrs to fix

    Method removeDotSegments has 60 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        public static function removeDotSegments( string $urlPath ): string {
            $output = '';
            $inputOffset = 0;
            $inputLength = strlen( $urlPath );
    
    
    Severity: Major
    Found in includes/utils/UrlUtils.php - About 2 hrs to fix

      Method expand has 53 lines of code (exceeds 25 allowed). Consider refactoring.
      Open

          public function expand( string $url, $defaultProto = PROTO_FALLBACK ): ?string {
              if ( $defaultProto === PROTO_CANONICAL ) {
                  $serverUrl = $this->canonicalServer;
              } elseif ( $defaultProto === PROTO_INTERNAL ) {
                  $serverUrl = $this->internalServer;
      Severity: Major
      Found in includes/utils/UrlUtils.php - About 2 hrs to fix

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

            public static function assemble( array $urlParts ): string {
                $result = '';
        
                if ( isset( $urlParts['delimiter'] ) ) {
                    if ( isset( $urlParts['scheme'] ) ) {
        Severity: Minor
        Found in includes/utils/UrlUtils.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 assemble has 30 lines of code (exceeds 25 allowed). Consider refactoring.
        Open

            public static function assemble( array $urlParts ): string {
                $result = '';
        
                if ( isset( $urlParts['delimiter'] ) ) {
                    if ( isset( $urlParts['scheme'] ) ) {
        Severity: Minor
        Found in includes/utils/UrlUtils.php - About 1 hr to fix

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

              public function __construct( array $options = [] ) {
                  foreach ( $options as $key => $value ) {
                      switch ( $key ) {
                          case self::SERVER:
                          case self::CANONICAL_SERVER:
          Severity: Minor
          Found in includes/utils/UrlUtils.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 parse has a Cognitive Complexity of 9 (exceeds 5 allowed). Consider refactoring.
          Open

              public function parse( string $url ): ?array {
                  // Protocol-relative URLs are handled really badly by parse_url(). It's so bad that the
                  // easiest way to handle them is to just prepend 'http:' and strip the protocol out later.
                  $wasRelative = str_starts_with( $url, '//' );
                  if ( $wasRelative ) {
          Severity: Minor
          Found in includes/utils/UrlUtils.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 matchesDomainList has a Cognitive Complexity of 7 (exceeds 5 allowed). Consider refactoring.
          Open

              public function matchesDomainList( string $url, array $domains ): bool {
                  $bits = $this->parse( $url );
                  if ( is_array( $bits ) && isset( $bits['host'] ) ) {
                      $host = '.' . $bits['host'];
                      foreach ( $domains as $domain ) {
          Severity: Minor
          Found in includes/utils/UrlUtils.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