wikimedia/mediawiki-core

View on GitHub
includes/Request/PathRouter.php

Summary

Maintainability
D
1 day
Test Coverage

Function extractTitle has a Cognitive Complexity of 38 (exceeds 5 allowed). Consider refactoring.
Open

    protected static function extractTitle( $path, $pattern ) {
        // Convert the path pattern into a regexp we can match with
        $regexp = preg_quote( $pattern->path, '#' );
        // .* for the $1
        $regexp = preg_replace( '#\\\\\$1#u', '(?P<par1>.*)', $regexp );
Severity: Minor
Found in includes/Request/PathRouter.php - About 5 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 doAdd has a Cognitive Complexity of 21 (exceeds 5 allowed). Consider refactoring.
Open

    protected function doAdd( $path, $params, $options, $key = null ) {
        // Make sure all paths start with a /
        if ( $path[0] !== '/' ) {
            $path = '/' . $path;
        }
Severity: Minor
Found in includes/Request/PathRouter.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 extractTitle has 56 lines of code (exceeds 25 allowed). Consider refactoring.
Open

    protected static function extractTitle( $path, $pattern ) {
        // Convert the path pattern into a regexp we can match with
        $regexp = preg_quote( $pattern->path, '#' );
        // .* for the $1
        $regexp = preg_replace( '#\\\\\$1#u', '(?P<par1>.*)', $regexp );
Severity: Major
Found in includes/Request/PathRouter.php - About 2 hrs to fix

    Method doAdd has 42 lines of code (exceeds 25 allowed). Consider refactoring.
    Open

        protected function doAdd( $path, $params, $options, $key = null ) {
            // Make sure all paths start with a /
            if ( $path[0] !== '/' ) {
                $path = '/' . $path;
            }
    Severity: Minor
    Found in includes/Request/PathRouter.php - About 1 hr to fix

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

          protected static function makeWeight( $pattern ) {
              # Start with a weight of 0
              $weight = 0;
      
              // Explode the path to work with
      Severity: Minor
      Found in includes/Request/PathRouter.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

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

          protected static function expandParamValue( $pathMatches, $key, $value ) {
              $error = false;
      
              $replacer = static function ( $m ) use ( $pathMatches, $key, &$error ) {
                  if ( $m[1] == "key" ) {
      Severity: Minor
      Found in includes/Request/PathRouter.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

      Avoid too many return statements within this method.
      Open

              return $value;
      Severity: Major
      Found in includes/Request/PathRouter.php - About 30 mins to fix

        Avoid too many return statements within this method.
        Open

                    return false;
        Severity: Major
        Found in includes/Request/PathRouter.php - About 30 mins to fix

          There are no issues that match your filters.

          Category
          Status